Skip to content

Commit

Permalink
ca_nb_fredericton: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Nov 6, 2018
1 parent 27b72cd commit 7e0f366
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ca_nb_fredericton/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@ def scrape(self):
councillors = page.xpath('//div[contains(@class, "view-people")]//div[contains(@class, "views-row")]')
assert len(councillors), 'No councillors found'
for councillor in councillors:
name = councillor.xpath('.//div[@property="dc:title"]')[0].text_content()
role_and_district = councillor.xpath('.//div[contains(@class, "field-name-field-sub-title")]//p')[-2].text_content().replace('\xa0', ' ')
name = councillor.xpath('.//div[@property="dc:title"]//text()')[0]
paras = councillor.xpath('.//div[contains(@class, "field-name-field-sub-title")]//p/text()')

if role_and_district == 'Mayor':
if paras[0] == 'Mayor':
district = 'Fredericton'
role = 'Mayor'
else:
district = role_and_district.split(', ', 1)[1]
if paras[0] == 'Deputy Mayor':
index = 1
else:
index = 0

district = paras[index].replace('\xa0', ' ').split(', ', 1)[1]
role = 'Councillor'

url = councillor.xpath('.//@href')[0]
page = self.lxmlize(url)

p = Person(primary_org='legislature', name=name, district=district, role=role)
p.add_source(COUNCIL_PAGE)
p.add_source(url)

p.image = councillor.xpath('.//img[@typeof="foaf:Image"]/@src')[0]
p.add_contact('email', self.get_email(page))
p.add_contact('voice', self.get_phone(page, area_codes=[506]), 'legislature')
p.add_source(COUNCIL_PAGE)
p.add_source(url)

yield p

0 comments on commit 7e0f366

Please sign in to comment.