diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bab6b123..4b33732c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,6 +11,6 @@ repos: - id: flake8 additional_dependencies: [flake8-comprehensions] - repo: https://github.com/pycqa/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort diff --git a/ca_ab/people.py b/ca_ab/people.py index a4ff29ca..e25ad7ec 100644 --- a/ca_ab/people.py +++ b/ca_ab/people.py @@ -1,6 +1,6 @@ import csv -from itertools import zip_longest from io import StringIO +from itertools import zip_longest from utils import CanadianPerson as Person from utils import CanadianScraper diff --git a/ca_bc_municipalities_candidates/people.py b/ca_bc_municipalities_candidates/people.py index 9a96b84f..109e4aa3 100644 --- a/ca_bc_municipalities_candidates/people.py +++ b/ca_bc_municipalities_candidates/people.py @@ -82,7 +82,7 @@ def scrape(self): birth_date = 1900 seen = set() - rows = [row for row in reader] + rows = list(reader) assert len(rows), "No councillors found" for row in rows: name = row["full name"] diff --git a/ca_on/people.py b/ca_on/people.py index c667d588..88b4e453 100644 --- a/ca_on/people.py +++ b/ca_on/people.py @@ -30,10 +30,9 @@ def scrape(self): '//div[@class="views-element-container block block-views block-views-blockmember-member-headshot"]//img/@src' ) - district = ''.join( + district = "".join( node.xpath( - '//div[@block="block-views-block-member-member-riding-block"]' - '//p[@class="riding"]//a//text()' + '//div[@block="block-views-block-member-member-riding-block"]' '//p[@class="riding"]//a//text()' ) ).strip() nodes = node.xpath('//div[@id="main-content"]//a') @@ -66,7 +65,7 @@ def scrape(self): '../following-sibling::div[@class="views-field views-field-nothing"]' '//span[@class="field-content"]' '//strong[contains(text(),"Tel.")]' - '/following-sibling::text()[1]' + "/following-sibling::text()[1]" )[0], error=False, ) diff --git a/ca_on_toronto/__init__.py b/ca_on_toronto/__init__.py index 8d40ddf9..869c1ea3 100644 --- a/ca_on_toronto/__init__.py +++ b/ca_on_toronto/__init__.py @@ -1,7 +1,8 @@ -from utils import CanadianJurisdiction from opencivicdata.divisions import Division from pupa.scrape import Organization +from utils import CanadianJurisdiction + class Toronto(CanadianJurisdiction): classification = "legislature" diff --git a/ca_on_toronto/people.py b/ca_on_toronto/people.py index 4641fdbc..010a9867 100644 --- a/ca_on_toronto/people.py +++ b/ca_on_toronto/people.py @@ -3,12 +3,12 @@ class TorontoPersonScraper(CSVScraper): # https://open.toronto.ca/dataset/elected-officials-contact-information/ - csv_url = 'https://ckan0.cf.opendata.inter.prod-toronto.ca/dataset/27aa4651-4548-4e57-bf00-53a346931251/resource/dea217a2-f7c1-4e62-aec1-48fffaad1170/download/2022-2026%20Elected%20Officials%20Contact%20Info.csv' + csv_url = "https://ckan0.cf.opendata.inter.prod-toronto.ca/dataset/27aa4651-4548-4e57-bf00-53a346931251/resource/dea217a2-f7c1-4e62-aec1-48fffaad1170/download/2022-2026%20Elected%20Officials%20Contact%20Info.csv" corrections = { - 'district name': { - 'Scarborough East': 'Scarborough-Guildwood', + "district name": { + "Scarborough East": "Scarborough-Guildwood", + }, + "email": { + "councillor_ mckelvie@toronto.ca": "councillor_mckelvie@toronto.ca", }, - 'email': { - 'councillor_ mckelvie@toronto.ca': 'councillor_mckelvie@toronto.ca', - } } diff --git a/ca_qc_trois_rivieres/people.py b/ca_qc_trois_rivieres/people.py index 8562f79d..954822f3 100644 --- a/ca_qc_trois_rivieres/people.py +++ b/ca_qc_trois_rivieres/people.py @@ -21,7 +21,7 @@ def scrape(self): email = self.lxmlize(url).xpath('//div[@class="content-page"]//a[starts-with(@href, "mailto:")]/@href')[0] email = re.sub("^mailto:", "", email) - name, district = map(lambda x: x.strip(), member.xpath(".//figcaption//text()")) + name, district = [x.strip() for x in member.xpath(".//figcaption//text()")] district = re.sub(r"\A(?:de|des|du) ", lambda match: match.group(0).lower(), district, flags=re.I) role = "Conseiller" diff --git a/ca_sk/people.py b/ca_sk/people.py index ae6f24c5..6f46fe52 100644 --- a/ca_sk/people.py +++ b/ca_sk/people.py @@ -16,18 +16,15 @@ def scrape(self): district = member.xpath("./td")[2].text_content() url = member.xpath("./td[1]/a/@href")[0] page = self.lxmlize(url) - party = page.xpath( - '//span[@id="ContentContainer_MainContent_ContentBottom_Property4"]' - '/span' - )[0].text + party = page.xpath('//span[@id="ContentContainer_MainContent_ContentBottom_Property4"]' "/span")[ + 0 + ].text p = Person(primary_org="legislature", name=name, district=district, role="MLA", party=party) p.add_source(COUNCIL_PAGE) p.add_source(url) try: - p.image = page.xpath( - '//div[contains(@class, "mla-image-cell")]/img/@src' - )[0] + p.image = page.xpath('//div[contains(@class, "mla-image-cell")]/img/@src')[0] except IndexError: pass