def form_bill_json_dict(xml_as_dict): """ Handles converting a government bulk XML file to legacy dictionary form. @param bill_id: id of the bill in format [type][number]-[congress] e.x. s934-113 @type bill_id: str @return: dictionary of bill attributes @rtype: dict """ bill_dict = xml_as_dict['billStatus']['bill'] bill_id = build_bill_id(bill_dict['billType'].lower(), bill_dict['billNumber'], bill_dict['congress']) titles = bill_info.titles_for(bill_dict['titles']['item']) actions = bill_info.actions_for(bill_dict['actions']['item'], bill_id, bill_info.current_title_for(titles, 'official')) status, status_date = bill_info.latest_status(actions, bill_dict.get('introducedDate', '')) bill_data = { 'bill_id': bill_id, 'bill_type': bill_dict.get('billType').lower(), 'number': bill_dict.get('billNumber'), 'congress': bill_dict.get('congress'), 'url': billstatus_url_for(bill_id), 'introduced_at': bill_dict.get('introducedDate', ''), 'by_request': bill_dict['sponsors']['item'][0]['byRequestType'] is not None, 'sponsor': bill_info.sponsor_for(bill_dict['sponsors']['item'][0]), 'cosponsors': bill_info.cosponsors_for(bill_dict['cosponsors']), 'actions': actions, 'history': bill_info.history_from_actions(actions), 'status': status, 'status_at': status_date, 'enacted_as': bill_info.slip_law_from(actions), 'titles': titles, 'official_title': bill_info.current_title_for(titles, 'official'), 'short_title': bill_info.current_title_for(titles, 'short'), 'popular_title': bill_info.current_title_for(titles, 'popular'), 'summary': bill_info.summary_for(bill_dict['summaries']['billSummaries']), # The top term's case has changed with the new bulk data. It's now in # Title Case. For backwards compatibility, the top term is run through # '.capitalize()' so it matches the old string. TODO: Remove one day? 'subjects_top_term': _fixup_top_term_case(bill_dict['policyArea']['name']) if bill_dict['policyArea'] else None, 'subjects': sorted( ([_fixup_top_term_case(bill_dict['policyArea']['name'])] if bill_dict['policyArea'] else []) + ([item['name'] for item in bill_dict['subjects']['billSubjects']['legislativeSubjects']['item']] if bill_dict['subjects']['billSubjects']['legislativeSubjects'] else []) ), 'related_bills': bill_info.related_bills_for(bill_dict['relatedBills']), 'committees': bill_info.committees_for(bill_dict['committees']['billCommittees']), 'amendments': bill_info.amendments_for(bill_dict['amendments']), 'updated_at': bill_dict.get('updateDate', ''), } return bill_data
def form_bill_json_dict(xml_as_dict): """ Handles converting a government bulk XML file to legacy dictionary form. @param bill_id: id of the bill in format [type][number]-[congress] e.x. s934-113 @type bill_id: str @return: dictionary of bill attributes @rtype: dict """ bill_dict = xml_as_dict['billStatus']['bill'] bill_id = build_bill_id(bill_dict['billType'].lower(), bill_dict['billNumber'], bill_dict['congress']) titles = bill_info.titles_for(bill_dict['titles']['item']) actions = bill_info.actions_for(bill_dict['actions']['item'], bill_id, bill_info.current_title_for(titles, 'official')) status, status_date = bill_info.latest_status(actions, bill_dict.get('introducedDate', '')) bill_data = { 'bill_id': bill_id, 'bill_type': bill_dict.get('billType').lower(), 'number': bill_dict.get('billNumber'), 'congress': bill_dict.get('congress'), 'url': billstatus_url_for(bill_id), 'introduced_at': bill_dict.get('introducedDate', ''), 'by_request': bill_dict['sponsors']['item'][0]['byRequestType'] is not None, 'sponsor': bill_info.sponsor_for(bill_dict['sponsors']['item'][0]), 'cosponsors': bill_info.cosponsors_for(bill_dict['cosponsors']), 'actions': actions, 'history': bill_info.history_from_actions(actions), 'status': status, 'status_at': status_date, 'enacted_as': bill_info.slip_law_from(actions), 'titles': titles, 'official_title': bill_info.current_title_for(titles, 'official'), 'short_title': bill_info.current_title_for(titles, 'short'), 'popular_title': bill_info.current_title_for(titles, 'popular'), 'summary': bill_info.summary_for(bill_dict['summaries']['billSummaries']), # The top term's case has changed with the new bulk data. It's now in # Title Case. For backwards compatibility, the top term is run through # '.capitalize()' so it matches the old string. TODO: Remove one day? 'subjects_top_term': _fixup_top_term_case(bill_dict['policyArea']['name']) if bill_dict['policyArea'] else None, 'subjects': sorted( ([_fixup_top_term_case(bill_dict['policyArea']['name'])] if bill_dict['policyArea'] else []) + ([item['name'] for item in bill_dict['subjects']['billSubjects']['legislativeSubjects']['item']] if bill_dict['subjects']['billSubjects']['legislativeSubjects'] else []) ), 'related_bills': bill_info.related_bills_for(bill_dict['relatedBills']), 'committees': bill_info.committees_for(bill_dict['committees']['billCommittees']), 'amendments': bill_info.amendments_for(bill_dict['amendments']), 'committee_reports': bill_info.committee_reports_for(bill_dict['committeeReports']), 'updated_at': bill_dict.get('updateDate', ''), } return bill_data
def test_summary(self): bill_id = "hr547-113" bill_html = fixtures.open_bill(bill_id) expected_summary = "Border Security and Responsibility Act 2013 - Directs the Secretary of Homeland Security (DHS), the Secretary of the Interior, the Secretary of Agriculture (USDA), the Secretary of Defense (DOD), and the Secretary of Commerce, in consultation with tribal, state, and local officials, to submit to Congress a border protection strategy for the international land borders of the United States. Specifies strategy elements.\n\nAmends the the Illegal Immigration Reform and Immigrant Responsibility Act of 1996 to revise international land border security provisions, including: (1) eliminating existing southwest border fencing requirements; (2) requiring that border control actions be in accordance with the border strategy required under this Act; and (3) giving priority to the use of remote cameras, sensors, removal of nonnative vegetation, incorporation of natural barriers, additional manpower, unmanned aerial vehicles, or other low impact border enforcement techniques.\n\nProhibits construction of border fencing, physical barriers, roads, lighting, cameras, sensors, or other tactical infrastructure prior to 90 days after such border strategy's submission to Congress.\n\nDirects the Secretary of Homeland Security, in consultation with the Secretary of the Interior, the Secretary of Agriculture, the Secretary of Defense, the Secretary of Commerce, and the heads of appropriate state and tribal wildlife agencies, to implement a comprehensive monitoring and mitigation plan to address the ecological and environmental impacts of security infrastructure and activities along the international land borders of the United States. Specifies plan requirements." summary_text = bill_info.summary_for(bill_html)['text'] self.assertEqual(summary_text, expected_summary)