Skip to content

Commit

Permalink
ca_on_mississauga: Simplify district/name split
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Nov 4, 2024
1 parent 3e2503d commit 26b8e72
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions ca_on_mississauga/people.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from utils import CanadianPerson as Person
from utils import CanadianScraper

Expand All @@ -23,14 +25,7 @@ def councillor_data(self, url):
page = self.lxmlize(url)

name_district = page.xpath('//*[@id="com-main"]/div/div/div/h1/text()')[0]
name_district_parts = name_district.split()
district = f"{name_district_parts[0]} {name_district_parts[1]}"
# Remove the first 3 elements of the name_district_parts which should include the district + '-'
name_district_parts.pop(0)
name_district_parts.pop(0)
name_district_parts.pop(0)
name = " ".join(name_district_parts)
name = name.replace("Councillor and Deputy Mayor", "").strip()
district, name = re.split(r" – (?:Councillor (?:and Deputy Mayor )?)?", name_district) # n-dash
email = self.get_email(page, '//section[contains(@class, "module-content")]')
photo = page.xpath(
'//section[contains(@class, "module-content")]/p[1]/img/@src|//section[contains(@class, "module-content")]/p[1]/b/img/@src|//section[contains(@class, "module-content")]/p[1]/strong/img/@src'
Expand All @@ -48,7 +43,7 @@ def mayor_data(self, url):
page = self.lxmlize(url)

name = page.xpath('//*[@id="com-main"]/div/div/div/h1/text()')[0]
name = name.replace("Mayor – ", "").strip()
name = name.replace("Mayor – ", "")
photo = page.xpath('//*[@id="65a01af8598b7"]/p[1]/img/@src')[0]

p = Person(primary_org="legislature", name=name, district="Mississauga", role="Mayor")
Expand Down

0 comments on commit 26b8e72

Please sign in to comment.