本文整理汇总了Python中pupa.scrape.Bill.legislative_session方法的典型用法代码示例。如果您正苦于以下问题:Python Bill.legislative_session方法的具体用法?Python Bill.legislative_session怎么用?Python Bill.legislative_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Bill
的用法示例。
在下文中一共展示了Bill.legislative_session方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import legislative_session [as 别名]
def scrape(self):
for leg_summary in self.legislation(created_after=datetime.datetime(2014, 1, 1)) :
leg_type = BILL_TYPES[leg_summary['Type']]
bill = Bill(identifier=leg_summary['File\xa0#'],
title=leg_summary['Title'],
legislative_session=None,
classification=leg_type,
from_organization={"name":"New York City Council"})
bill.add_source(leg_summary['url'])
leg_details = self.legDetails(leg_summary['url'])
history = self.history(leg_summary['url'])
bill.add_title(leg_details['Name'],
note='created by administrative staff')
if 'Summary' in leg_details :
bill.add_abstract(leg_details['Summary'], note='')
if leg_details['Law number'] :
bill.add_identifier(leg_details['Law number'],
note='law number')
for sponsorship in self._sponsors(leg_details.get('Sponsors', [])) :
sponsor, sponsorship_type, primary = sponsorship
bill.add_sponsorship(sponsor, sponsorship_type,
'person', primary,
entity_id = make_pseudo_id(name=sponsor))
for attachment in leg_details.get('Attachments', []) :
bill.add_document_link(attachment['label'],
attachment['url'],
media_type="application/pdf")
history = list(history)
if history :
earliest_action = min(self.toTime(action['Date'])
for action in history)
bill.legislative_session = self.sessions(earliest_action)
else :
bill.legislative_session = str(self.SESSION_STARTS[0])
for action in history :
action_description = action['Action']
if not action_description :
continue
action_class = ACTION_CLASSIFICATION[action_description]
action_date = self.toDate(action['Date'])
responsible_org = action['Action\xa0By']
if responsible_org == 'City Council' :
responsible_org = 'New York City Council'
elif responsible_org == 'Administration' :
responsible_org = 'Mayor'
if responsible_org == 'Town Hall Meeting' :
continue
else :
act = bill.add_action(action_description,
action_date,
organization={'name': responsible_org},
classification=action_class)
if 'url' in action['Action\xa0Details'] :
action_detail_url = action['Action\xa0Details']['url']
if action_class == 'committee-referral' :
action_details = self.actionDetails(action_detail_url)
referred_committee = action_details['Action text'].rsplit(' to the ', 1)[-1]
act.add_related_entity(referred_committee,
'organization',
entity_id = make_pseudo_id(name=referred_committee))
result, votes = self.extractVotes(action_detail_url)
if votes :
action_vote = VoteEvent(legislative_session=bill.legislative_session,
motion_text=action_description,
organization={'name': responsible_org},
classification=action_class,
start_date=action_date,
result=result,
bill=bill)
action_vote.add_source(action_detail_url)
for option, voter in votes :
action_vote.vote(option, voter)
yield action_vote
text = self.text(leg_summary['url'])
if text :
bill.extras = {'local_classification' : leg_summary['Type'],
'full_text' : text}
else :
bill.extras = {'local_classification' : leg_summary['Type']}
#.........这里部分代码省略.........
示例2: scrape
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import legislative_session [as 别名]
def scrape(self):
for agenda_item in self.agendaItems(date_from=self.start_date, date_to=self.end_date):
# TODO: Add agenda_item type to OCD
leg_type = "bill"
title = agenda_item["Title"].replace("\n", " ")
title_re = re.compile(
"^(.+?)(?: - (?:by )?((?:Deputy )?Mayor|Councillor) (.+), seconded by ((?:Deputy )?Mayor|Councillor) (.+))?$"
)
title, primary_role, primary_sponsor, secondary_role, secondary_sponsor = re.match(title_re, title).groups()
b = Bill(
identifier=agenda_item["Item No."],
title=title,
legislative_session=None,
classification=leg_type,
from_organization={"name": self.jurisdiction.name},
)
b.add_source(agenda_item["url"], note="web")
if primary_sponsor and secondary_sponsor:
b.add_sponsorship(primary_sponsor, "mover", "person", True)
b.add_sponsorship(secondary_sponsor, "seconder", "person", False)
# TODO: Fake session for now
b.legislative_session = "2014-2018"
agenda_item_versions = self.agendaItemVersions(agenda_item["url"])
# Use one version's full_text (will be most recent)
b.extras["full_text"] = agenda_item_versions[0]["full_text"]
for version in agenda_item_versions:
action_date = self.toDate(version["date"])
if "Summary" in version["sections"]:
# TODO: Investigate whether these vary between versions, as
# we perhaps don't need to add one for each
b.add_abstract(version["sections"]["Summary"], note="", date=action_date)
if not version["action"]:
continue
if re.match(r"\d+:\d+ [A|P]M", version["action"]):
continue
action_description = version["action"]
responsible_org = version["responsible_org"]
action_class = ACTION_CLASSIFICATION.get(version["action"])
def is_recommendation(version):
return any("Recommendations" in s for s in version["sections"].keys())
if responsible_org == "City Council":
responsible_org = self.jurisdiction.name
else:
if action_class == "passage":
action_class = "committee-passage"
if is_recommendation(version):
action_class = "committee-passage-favorable"
b.add_action(
action_description, action_date, organization={"name": responsible_org}, classification=action_class
)
yield b