The list of municipalities was found on the CRA website, https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/municipalities.html#List.
In [2]:
import pandas as pd
In [3]:
CRA_LIST_OF_MUNICIPALITIES = {
'Alberta': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-alberta.html',
'British Columbia': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-british-columbia.html',
'Manitoba': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-manitoba.html',
'New Brunswick': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-new-brunswick.html',
'Newfoundland and Labrador': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-newfoundland-labrador.html',
'Northwest Territories': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-northwest-territories.html',
'Nova Scotia': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-nova-scotia.html',
'Nunavut': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-nunavut.html',
'Ontario': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-ontario.html',
'Prince Edward Island': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-prince-edward-island.html',
'Quebec': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-quebec.html',
'Saskatchewan': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-saskatchewan.html',
'Yukon': 'https://www.canada.ca/en/revenue-agency/services/charities-giving/other-organizations-that-issue-donation-receipts-qualified-donees/other-qualified-donees-listings/list-municipalities-yukon.html',
}
In [4]:
dfs = []
for province, website in CRA_LIST_OF_MUNICIPALITIES.items():
df = pd.read_html(website)[0]
df['Province'] = province
dfs.append(df)
df = pd.concat(dfs)
df.tail()
Out[4]:
In [5]:
df = df[['Name', 'Province', 'Type', 'Status', 'Effective date', 'Notes']]
df['Effective date'] = pd.to_datetime(df['Effective date'])
df = df.rename(columns={'Name': 'name', 'Province': 'province', 'Type': 'type',
'Status': 'status', 'Effective date': 'effective_date', 'Notes': 'notes'})
df.tail()
Out[5]:
In [6]:
import datetime
df.to_csv('list-of-canadian-municipalities.csv'.format(datetime.date.today()))
In [8]:
with open('list-of-canadian-municipalities.json', 'w') as fobj:
fobj.write(df.to_json(orient='table'))
In [ ]: