本文整理汇总了Python中pupa.scrape.Bill.other_titles方法的典型用法代码示例。如果您正苦于以下问题:Python Bill.other_titles方法的具体用法?Python Bill.other_titles怎么用?Python Bill.other_titles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pupa.scrape.Bill
的用法示例。
在下文中一共展示了Bill.other_titles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_bills
# 需要导入模块: from pupa.scrape import Bill [as 别名]
# 或者: from pupa.scrape.Bill import other_titles [as 别名]
def scrape_bills(self):
"""
Does the following
1) Scrapes bill data from unitedstates project and saves the data to path specified in UnitedStates module
2) Iterates over bill data and converts each one to an OCD-compliant bill model.
3) Yields the OCD-compliant bill model instance
@return: yield Bill instance
"""
# run scraper first to pull in all the bill data
self.run_unitedstates_bill_scraper()
# iterate over all the files and build and yield Bill objects
for filename in find_files(settings.SCRAPED_DATA_DIR, '.*[a-z]*\/[a-z]*[0-9]*\/data\.json'):
try:
with open(filename) as json_file:
json_data = json.load(json_file)
# Initialize Object
bill = Bill(self.TYPE_MAP[json_data['bill_type']]['canonical'] + ' ' + json_data['number'],
json_data['congress'],
json_data['official_title'],
chamber=self.TYPE_MAP[json_data['bill_type']]['chamber']
)
# Basics
bill.type = [json_data['bill_type']]
bill.subject = json_data['subjects']
bill.add_summary(json_data['summary']['as'],
json_data['summary']['text'],
json_data['summary']['date'])
# Common Fields
bill.sources = [{'url': json_data['url'], 'note': 'all'}]
# Other/Related Bills
bill.other_titles = [{'note': t['type'], 'title': t['title']} for t in json_data['titles']]
# change value of relationship_type to 'type' field from json_data when permitted by schema
bill.related_bills = [{'session': b['session'], 'name': b['name'], 'relationship_type':'companion'}
for b in json_data['related_bills']]
# add primary sponsor
bill.add_sponsorship_by_identifier(json_data['sponsor']['name'], 'person', 'person', True,
scheme='thomas_id',
identifier=json_data['sponsor']['thomas_id'],
chamber=self.TYPE_MAP[json_data['bill_type']]['chamber'])
# add cosponsors
for cs in json_data['cosponsors']:
bill.add_sponsorship_by_identifier(cs['name'], 'person', 'person', False,
scheme='thomas_id', identifier=cs['thomas_id'],
chamber=self.TYPE_MAP[json_data['bill_type']]['chamber'])
# add introduced_at and actions
bill.actions.append({'date': json_data['introduced_at'], 'type': 'introduced',
'description': 'date of introduction',
'actor': self.TYPE_MAP[json_data['bill_type']]['chamber'],
'related_entities': []})
for action in json_data['actions']:
bill.actions.append({'date': action['acted_at'],
'type': [action['type']],
'description': action['text'],
'actor': self.TYPE_MAP[json_data['bill_type']]['chamber'],
'related_entities': []
})
# add bill versions
for version_path in find_files(os.path.join(settings.SCRAPED_DATA_DIR,
'data', bill.session, 'bills', json_data['bill_type'],
json_data['bill_type'] + json_data['number'],
'text-versions'), '*\.json'):
try:
with open(version_path) as version_file:
version_json_data = json.load(version_file)
for k, v in version_json_data['urls'].iteritems():
bill.versions.append({'date': version_json_data['issued_on'],
'type': version_json_data['version_code'],
'name': self.VERSION_MAP[version_json_data['version_code']],
'links': [{'mimetype': k, 'url': v}]})
except IOError:
print("Unable to open or parse file with path " + version_path)
continue
yield bill
except IOError:
print("Unable to open or parse file with path " + filename)
continue