-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into mississauga_fix_2
- Loading branch information
Showing
7 changed files
with
64 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,31 @@ | ||
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') | ||
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(" - ") | ||
|
||
for i in range(0, len(councillors), 2): | ||
role_name, contact_info = councillors[i], councillors[i + 1] | ||
role, name = role_name.text_content().strip().replace("\xa0", " ").split("— ") | ||
|
||
# "Ward 1 Councillor" | ||
if "Councillor" in role: | ||
district = role.split(" Councillor")[0] | ||
role = "Councillor" | ||
# "Mayor", "Executive Officer to the Mayor and Council" | ||
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 | ||
|
||
|
||
def scrape_mayor(div, name): | ||
p = Person(primary_org="legislature", name=name, district="Wilmot", role="Mayor") | ||
p.add_source(COUNCIL_PAGE) | ||
|
||
address = div.xpath('.//div[@class="contactListAddress"]')[0].text_content() | ||
phone = div.xpath('.//div[@class="contactListMainNumber"]/a/text()')[0] | ||
other_phone = div.xpath('.//div[@class="contactListPhNumber"]/a/text()')[0] | ||
p.add_contact("address", address, "legislature") | ||
p.add_contact("voice", phone, "legislature") | ||
p.add_contact("voice", other_phone, "office") | ||
|
||
return p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters