'Extract the actions taken on a bill.
A bill can have actions taken from either chamber.  The current
chamber\'s actions will be the first table of actions. The other
chamber\'s actions will be in the second table.'

def extract_actions(self, bill, doc, current_chamber):

    bill_actions = list()
    action_tables = doc.xpath('//table[@class="actions"]')
    for cur_table in action_tables:
        for row in cur_table.xpath('.//tr'):
            bill_action = dict()
            (date_col, the_rest) = row.xpath('td')
            action_date = date_col.text_content().strip()
            action_text = the_rest.text.strip()
            committee = the_rest.xpath("a[contains(@href,'committee')]/text()")
            extra = ''.join(the_rest.xpath('span[not(@style)]/text()    |    a/text()'))
            if (action_text in ('Chapter    number', 'See    also', 'See', 'Effective    date', 'Secretary    of    State')):
                continue
            try:
                action_date = datetime.datetime.strptime(action_date, '%m/%d/%Y').date()
            except ValueError:
                try:
                    action_date = datetime.datetime.strptime(extra, '%m/%d/%y').date()
                except ValueError:
                    try:
                        action_date = datetime.datetime.strptime(extra, '%m/%d/%Y').date()
                    except ValueError:
                        self.warning(('ACTION    without    date:    %s' % action_text))
                        continue
            action_type = None
            for (pattern, atype) in self._categorizers:
                if re.match(pattern, action_text):
                    action_type = atype
                    if (('referral-committee' in action_type) and (len(committee) > 0)):
                        bill_action['committees'] = committee[0]
                    break
            if extra:
                action_text += ('    ' + extra)
            bill_action['action_text'] = action_text
            if isinstance(action_type, list):
                for atype in action_type:
                    if ((atype is not None) and atype.startswith('governor')):
                        bill_action['action_chamber'] = 'executive'
                        break
                else:
                    bill_action['action_chamber'] = current_chamber
            elif ((action_type is not None) and action_type.startswith('governor')):
                bill_action['action_chamber'] = 'executive'
            else:
                bill_action['action_chamber'] = current_chamber
            bill_action['action_date'] = action_date
            bill_action['action_type'] = action_type
            bill_actions.append(bill_action)
        if (current_chamber == 'upper'):
            current_chamber = 'lower'
        else:
            current_chamber = 'upper'
    for action in bill_actions:
        act = bill.add_action(action['action_text'], action['action_date'], chamber=action['action_chamber'], classification=action['action_type'])
        if ('committees' in action):
            committee = action['committees']
            act.add_related_entity(committee, 'organization', entity_id=_make_pseudo_id(name=committee))
    return bill
