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

Kirkland scraper #437

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_schedule: quarterly
skip: [pip-compile]
default_language_version:
python: python3.10
python: python3.11
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
Expand Down
24 changes: 19 additions & 5 deletions ca_qc_kirkland/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@

class KirklandPersonScraper(CanadianScraper):
def scrape(self):
page = self.lxmlize(COUNCIL_PAGE)
def decode_email(e):
de = ""
k = int(e[:2], 16)

councillors = page.xpath('//div[@class="container_content"]//tbody/tr')
for i in range(2, len(e) - 1, 2):
de += chr(int(e[i : i + 2], 16) ^ k)

return de

page = self.lxmlize(COUNCIL_PAGE, "iso-8859-1")

councillors = page.xpath('//table/tbody[not(@id)]/tr/td[@valign="top"]')
assert len(councillors), "No councillors found"
for councillor in councillors:
if councillor == councillors[0]:
Expand All @@ -23,19 +32,24 @@ def scrape(self):

name = councillor.xpath(".//strong/text()")[0]

# Using self.get_phone does not include the extension #
phone = (
councillor.xpath('.//div[contains(text(), "#")]/text()')[0]
.replace("T ", "")
.replace(" ", "-")
.replace(".", ",") # correcting a typo
.replace(".", ",")
.replace(",-#-", " x")
)
email = self.get_email(councillor)
encrypted_email = councillor.xpath('.//@href[contains(., "email")]')[0].split("#")[1]
email = decode_email(encrypted_email)

# cloudflare encrypts the email data
email = councillor.xpath(".//div/*/*/@href | .//div/*/@href | .//@href")[0]
decoded_email = decode_email(email.split("#", 1)[1])
p = Person(primary_org="legislature", name=name, district=district, role=role)
p.add_source(COUNCIL_PAGE)
p.add_contact("voice", phone, "legislature")
p.add_contact("email", email)
p.add_contact("email", decoded_email)
image = councillor.xpath(".//img/@src")
if image:
p.image = image[0]
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ sqlparse==0.5.1
# via django
text-unidecode==1.3
# via python-slugify
typing-extensions==4.12.2
# via asgiref
unidecode==0.4.14
# via -r requirements.in
urllib3==1.26.20
Expand Down