本文整理汇总了Python中pupa.scrape.Bill.extras[key]方法的典型用法代码示例。如果您正苦于以下问题:Python Bill.extras[key]方法的具体用法?Python Bill.extras[key]怎么用?Python Bill.extras[key]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Bill
的用法示例。
在下文中一共展示了Bill.extras[key]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_bill_status_page
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import extras[key] [as 别名]
def parse_bill_status_page(self, url, page, session, chamber):
# see 2007 HB 2... weird.
parsed_url = urllib.parse.urlparse(url)
parsed_query = dict(urllib.parse.parse_qsl(parsed_url.query))
bill_id = "{0} {1}".format(
parsed_query['P_BLTP_BILL_TYP_CD'],
parsed_query['P_BILL_NO1'])
try:
xp = '//b[text()="Short Title:"]/../following-sibling::td/text()'
title = page.xpath(xp).pop()
except IndexError:
title = page.xpath('//tr[1]/td[2]')[0].text_content()
# Add bill type.
_bill_id = bill_id.lower()
if 'b' in _bill_id:
classification = 'bill'
elif 'j' in _bill_id or 'jr' in _bill_id:
classification = 'joint resolution'
elif 'cr' in _bill_id:
classification = 'concurrent resolution'
elif 'r' in _bill_id:
classification = 'resolution'
bill = Bill(bill_id, legislative_session=session, chamber=chamber,
title=title, classification=classification)
self.add_actions(bill, page)
votes = self.add_votes(bill, page, url)
tabledata = self._get_tabledata(page)
# Add sponsor info.
bill.add_sponsorship(tabledata['primary sponsor:'][0], classification='primary',
entity_type='person', primary=True)
# A various plus fields MT provides.
plus_fields = [
'requester',
('chapter number:', 'chapter'),
'transmittal date:',
'drafter',
'fiscal note probable:',
'bill draft number:',
'preintroduction required:',
'by request of',
'category:']
for x in plus_fields:
if isinstance(x, tuple):
_key, key = x
else:
_key = key = x
key = key.replace(' ', '_')
try:
val = tabledata[_key]
except KeyError:
continue
if len(val) == 1:
val = val[0]
bill.extras[key] = val
# Add bill subjects.
xp = '//th[contains(., "Revenue/Approp.")]/ancestor::table/tr'
subjects = []
for tr in page.xpath(xp):
try:
subj = tr.xpath('td')[0].text_content()
except IndexError:
continue
subjects.append(subj)
for s in subjects:
bill.add_subject(s)
self.add_fiscal_notes(page, bill)
return bill, list(votes)
示例2: parse_bill_status_page
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import extras[key] [as 别名]
def parse_bill_status_page(self, status_url, bill_url, session, chamber):
status_page = lxml.html.fromstring(self.get(status_url).text)
# see 2007 HB 2... weird.
bill_re = r'.*?/([A-Z]+)0*(\d+)\.pdf'
bill_xpath = '//a[contains(@href, ".pdf") and contains(@href, "billpdf")]/@href'
bill_id = re.search(bill_re, status_page.xpath(bill_xpath)[0],
re.IGNORECASE).groups()
bill_id = "{0} {1}".format(bill_id[0], int(bill_id[1]))
try:
xp = '//b[text()="Short Title:"]/../following-sibling::td/text()'
title = status_page.xpath(xp).pop()
except IndexError:
title = status_page.xpath('//tr[1]/td[2]')[0].text_content()
# Add bill type.
_bill_id = bill_id.lower()
if 'b' in _bill_id:
classification = 'bill'
elif 'j' in _bill_id or 'jr' in _bill_id:
classification = 'joint resolution'
elif 'cr' in _bill_id:
classification = 'concurrent resolution'
elif 'r' in _bill_id:
classification = 'resolution'
bill = Bill(bill_id, legislative_session=session, chamber=chamber,
title=title, classification=classification)
self.add_actions(bill, status_page)
votes = self.add_votes(bill, status_page, status_url)
tabledata = self._get_tabledata(status_page)
# Add sponsor info.
bill.add_sponsorship(tabledata['primary sponsor:'][0], classification='primary',
entity_type='person', primary=True)
# A various plus fields MT provides.
plus_fields = [
'requester',
('chapter number:', 'chapter'),
'transmittal date:',
'drafter',
'fiscal note probable:',
'bill draft number:',
'preintroduction required:',
'by request of',
'category:']
for x in plus_fields:
if isinstance(x, tuple):
_key, key = x
else:
_key = key = x
key = key.replace(' ', '_')
try:
val = tabledata[_key]
except KeyError:
continue
if len(val) == 1:
val = val[0]
bill.extras[key] = val
# Add bill subjects.
xp = '//th[contains(., "Revenue/Approp.")]/ancestor::table/tr'
subjects = []
for tr in status_page.xpath(xp):
try:
subj = tr.xpath('td')[0].text_content()
except:
continue
subjects.append(subj)
for s in subjects:
bill.add_subject(s)
self.add_fiscal_notes(status_page, bill)
return bill, list(votes)