本文整理汇总了Python中utils.CanadianLegislator.party方法的典型用法代码示例。如果您正苦于以下问题:Python CanadianLegislator.party方法的具体用法?Python CanadianLegislator.party怎么用?Python CanadianLegislator.party使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.CanadianLegislator
的用法示例。
在下文中一共展示了CanadianLegislator.party方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_people
# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import party [as 别名]
def get_people(self):
page = lxmlize(COUNCIL_PAGE)
councillors = page.xpath('//table[@cellpadding="3"]//td//a/@href')
for councillor in councillors:
page = lxmlize(councillor)
name = page.xpath('//b[contains(text(), "MLA:")]')[0].text_content().replace('MLA:', '').replace('Hon.', '').replace(', Q.C.', '').strip()
district = page.xpath('//em/strong/text()')[0].strip()
p = Legislator(name=name, post_id=district, role='MLA')
p.add_source(COUNCIL_PAGE)
p.add_source(councillor)
p.image = page.xpath('//a[contains(@href, "images/members")]/@href')[0]
party_caps = page.xpath('string((//table[@width=440]//b)[last()])')
p.party = party_caps.strip().title().replace('Of', 'of')
email = page.xpath('//a[contains(@href, "mailto:")]/text()')[0]
p.add_contact('email', email, None)
office = ', '.join(page.xpath('//i/b[contains(text(), "Office:")]/ancestor::p/text()'))
office = re.sub(r'\s{2,}', ' ', office)
p.add_contact('address', office, 'legislature')
constituency = page.xpath('//i/b[contains(text(), "Constituency:")]/ancestor::p/text()')
if not 'TBD' in constituency[0]:
constituency = re.sub(r'\s{2,}', ' ', ', '.join(constituency))
p.add_contact('address', constituency, 'constituency')
phones = page.xpath('//strong[contains(text(), "Phone:")]/ancestor::tr[1]')[0]
office_phone = phones.xpath('./td[2]//text()')[0].strip().replace(' ', '-')
p.add_contact('voice', office_phone, 'legislature')
constituency_phone = phones.xpath('./td[4]//text()')[0].strip().replace(' ', '-')
if not 'TBD' in constituency_phone:
p.add_contact('voice', constituency_phone, 'constituency')
faxes = page.xpath('//strong[contains(text(), "Fax:")]/ancestor::tr[1]')[0]
office_fax = faxes.xpath('./td[2]//text()')[0].strip().replace(' ', '-')
p.add_contact('fax', office_fax, 'legislature')
constituency_fax = faxes.xpath('./td[4]//text()')[0].strip().replace(' ', '-')
if not 'TBD' in constituency_fax:
p.add_contact('fax', constituency_fax, 'constituency')
yield p