def apply_votes(self, bill): """Given a bill (and assuming it has a status_url in its dict), parse all of the votes """ bill_votes = votes.all_votes_for_url(self, bill['status_url']) for (chamber,vote_desc,pdf_url,these_votes) in bill_votes: try: date = vote_desc.split("-")[-1] except IndexError: self.warning("[%s] Couldn't get date out of [%s]" % (bill['bill_id'],vote_desc)) continue yes_votes = [] no_votes = [] other_votes = [] for voter,vote in these_votes.iteritems(): if vote == 'Y': yes_votes.append(voter) elif vote == 'N': no_votes.append(voter) else: other_votes.append(voter) passed = len(yes_votes) > len(no_votes) # not necessarily correct, but not sure where else to get it. maybe from pdf vote = Vote(standardize_chamber(chamber),date,vote_desc,passed, len(yes_votes), len(no_votes), len(other_votes),pdf_url=pdf_url) for voter in yes_votes: vote.yes(voter) for voter in no_votes: vote.no(voter) for voter in other_votes: vote.other(voter) bill.add_vote(vote)
def extract_actions(s): actions = [] anchor = s("a",{'name':'actions'})[0] table = None for x in anchor.nextGenerator(): if hasattr(x,'name') and getattr(x,'name') == 'table': table = x break if table: cells = table("td", { "class": "content" }) # markup bad: only header row correctly wrapped in a "tr"! while cells: (date,chamber,action) = cells[0:3] date = get_text(date).replace(" "," ").strip() chamber = standardize_chamber(get_text(chamber).lower()) cells = cells[3:] action = get_text(action) actions.append((chamber,action,date)) return actions