def parse_actions(self, bill, page): chamber = bill['chamber'] for tr in page.xpath("//td[text() = 'Actions:']/" "following-sibling::td/table/tr"): action = tr.xpath("string()").replace(u'\xa0', ' ').strip() if action == 'In the House': chamber = 'lower' continue elif action == 'In the Senate': chamber = 'upper' continue elif action.startswith("(Remarks see"): continue match = re.match( r"(.*),\s+(\w+\.?\s+\d{1,2},\s+\d{4})( \(\d+-\d+\))?", action) if not match: continue action = match.group(1) type = [] if action.lower().startswith('introduced'): type.append('bill:introduced') elif action.startswith('Referred to'): type.append('committee:referred') elif action.startswith('Re-referred'): type.append('committee:referred') elif action.startswith('Amended on'): type.append('amendment:passed') elif action.startswith('Approved by the Governor'): type.append('governor:signed') elif action.startswith('Presented to the Governor'): type.append('governor:received') elif action == 'Final passage': type.append('bill:passed') if re.search('concurred in (House|Senate) amendments', action): if re.search(', as amended by the (House|Senate)', action): type.append('amendment:amended') type.append('amendment:passed') if not type: type = ['other'] date = parse_action_date(match.group(2)) bill.add_action(chamber, action, date, type=type)
def parse_actions(self, bill, page): chamber = bill['chamber'] for tr in page.xpath("//td[text() = 'Actions:']/" "following-sibling::td/table/tr"): action = tr.xpath("string()").replace(u'\xa0', ' ').strip() if action == 'In the House': chamber = 'lower' continue elif action == 'In the Senate': chamber = 'upper' continue match = re.match( r"(.*),\s+(\w+\.?\s+\d{1,2},\s+\d{4})( \(\d+-\d+\))?", action) if not match: continue action = match.group(1) date = parse_action_date(match.group(2)) bill.add_action(chamber, action, date, type=action_type(action))
def parse_actions(self, bill, history_page): """ Grab all of a bill's actions from its history page. """ act_table = history_page.find(text="Actions:").parent.findNextSibling() act_chamber = bill['chamber'] for row in act_table.findAll('tr'): act_raw = "" for node in row.td.div: if hasattr(node, 'contents'): if len(node.contents) > 0: act_raw += node.contents[0] else: act_raw += node act_raw = act_raw.replace(' ', ' ') act_match = re.match('(.*),\s+((\w+\.?) (\d+), (\d{4}))', act_raw) if act_match: date = parse_action_date(act_match.group(2).strip()) action = act_match.group(1).strip() type = action_type(action) bill.add_action(act_chamber, action, date, type=type) else: # Handle actions from the other chamber # ("In the (House|Senate)" row followed by actions that # took place in that chamber) cham_match = re.match('In the (House|Senate)', act_raw) if not cham_match: # Ignore? continue if cham_match.group(1) == 'House': act_chamber = 'lower' else: act_chamber = 'upper'