Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Wilmot scraper and add email contact #442

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions ca_on_wilmot/people.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
from utils import CanadianPerson as Person
from utils import CanadianScraper

COUNCIL_PAGE = "https://www.wilmot.ca/Modules/contact/search.aspx?s=EFHOVXSi8AOIMKMStZMNvAeQuAleQuAl"
COUNCIL_PAGE = "https://www.wilmot.ca/en/township-office/council.aspx"


class WilmotPersonScraper(CanadianScraper):
def scrape(self):
page = self.lxmlize(COUNCIL_PAGE)

councillors = page.xpath('//table[@class="contactList"]//tr')
councillors = page.xpath('.//table[@class="icrtAccordion"]//tr')
councillors = parse_counsillors(councillors)
assert len(councillors), "No councillors found"
for councillor in councillors:
name, role_district = councillor.xpath(".//button/text()")[0].split(" - ", 1)
if "Mayor" in role_district:
yield scrape_mayor(councillor, name)
continue
role, district = role_district.split(" - ")

role_name, contact_info = councillor
role_name = role_name.text_content().strip()
if "—\xa0" in role_name:
role, name = role_name.split("—\xa0")
else:
role, name = role_name.split("— ")

if "Councillor" in role:
district = role.split(" Councillor")[0]
role = "Councillor"
else:
district = "Wilmot"

phone = self.get_phone(contact_info)
email = self.get_email(contact_info)
p = Person(primary_org="legislature", name=name, district=district, role=role)
p.add_source(COUNCIL_PAGE)

phone = self.get_phone(councillor).replace("/", "")
p.add_contact("voice", phone, "legislature")
p.add_contact("email", email)
yield p


Expand All @@ -37,3 +46,7 @@ def scrape_mayor(div, name):
p.add_contact("voice", other_phone, "office")

return p


def parse_counsillors(councillors):
return [councillors[i : i + 2] for i in range(0, len(councillors), 2)]
jpmckinney marked this conversation as resolved.
Show resolved Hide resolved