def process_resolution_vote_chunk(chunk): chunk, line_numbers = chunk try: pass_status = [a for a in chunk if 'So the resolution' in a][0] except: print len(chunk) print chunk failed = "was not adopted" passed = "was adopted" if failed in pass_status: _pass = False elif passed in pass_status: _pass = True else: _pass = "******" _vote_aff = 'Those who voted in the affirmative' _vote_neg = 'Those who voted in the negative' affirmative_names, negative_names = [], [] negatives_and_affirmatives = getblock(chunk, _vote_aff, _vote_neg) if negatives_and_affirmatives: affirmatives = negatives_and_affirmatives negatives = getblock(chunk, _vote_neg, 'So the resolution') else: affirmatives = getblock(chunk, _vote_aff, 'So the resolution') negatives = getblock(chunk, _vote_neg, 'So the resolution') if affirmatives: # Pop off the inclusive end block match line affs = affirmatives[1:len(affirmatives) - 1] affirmative_names = parse_vote_name_block(affs) if negatives: neg = negatives[1:len(negatives) - 1] negative_names = parse_vote_name_block(neg) log_args = ( str("TODO: ") , len(affirmative_names) , len(negative_names) ) logger.info(" %s (amendment) - yays: %d, nays: %d" % log_args) return dict([ ('title', "TODO:") , ('affirmatives', affirmative_names) , ('negatives', negative_names) , ('pass', _pass) , ('status_string', pass_status) , ('yays', len(affirmative_names)) , ('nays', len(negative_names)) # TODO: these will need to be adjusted to re-include the # removed ^L lines. , ('source_document_range', line_numbers) ])
def process_vote_chunk(chunk): chunk, line_numbers = chunk if len(chunk) > 2000: logger.error(" * OMG, vote chunk much larger than it should be. ") logger.error(" * Parse error in finding vote chunk bounds.") logger.error(" * Chunk begins... ") logger.error(' > ' + '\n > '.join(chunk[0:5])) bill_title = False affirmative_names = [] negative_names = [] pass_status = [a for a in chunk if 'So the bill' in a][0] remove = [ "So the bill, as" , "So the bill, " , "So the bill " ] for a in remove: pass_status = pass_status.replace(a, '').replace('.', '').strip() if "failed" in pass_status: _pass = False elif "passed" in pass_status: _pass = True else: _pass = "******" if "as amended" in pass_status: amended = True else: amended = False # Look for title line for _l in chunk: if 'F. No.' in _l: bill_title_line = _l break if bill_title_line: try: bill_title = find_bill_title.search(bill_title_line).groups()[0] except: pass _vote_aff = 'Those who voted in the affirmative' _vote_neg = 'Those who voted in the negative' includes_negative = getblock(chunk, _vote_aff, _vote_neg) if includes_negative: affirmatives = includes_negative negatives = getblock(chunk, _vote_neg, 'So the bill') # Pop off the inclusive end block match line neg = negatives[1:len(negatives) - 1] negative_names = parse_vote_name_block(neg) else: affirmatives = getblock(chunk, _vote_aff, 'So the bill') negative_names = [] # Pop off the inclusive end block match line affs = affirmatives[1:len(affirmatives) - 1] affirmative_names = parse_vote_name_block(affs) log_args = ( str(bill_title) , len(affirmative_names) , len(negative_names) ) logger.info(" %s - yays: %d, nays: %d" % log_args) return dict([ ('title', bill_title) , ('pass', _pass) , ('status_string', pass_status) , ('amended', amended) , ('yays', len(affirmative_names)) , ('nays', len(negative_names)) , ('affirmatives', affirmative_names) , ('negatives', negative_names) # TODO: these will need to be adjusted to re-include the # removed ^L lines. , ('source_document_range', line_numbers) ])
def process_amendment_vote_chunk(chunk): chunk, line_numbers = chunk # Look for title line for _l in chunk: if 'F. No.' in _l: bill_title_line = _l break if bill_title_line: try: bill_title = find_bill_title.search(bill_title_line).groups()[0] except: pass try: pass_status = [a for a in chunk if a.startswith('The motion')][0] except: print len(chunk) print chunk failed = "did not prevail" passed = "prevailed" if failed in pass_status: _pass = False elif passed in pass_status: _pass = True else: _pass = "******" _vote_aff = 'Those who voted in the affirmative' _vote_neg = 'Those who voted in the negative' affirmative_names, negative_names = [], [] negatives_and_affirmatives = getblock(chunk, _vote_aff, _vote_neg) if negatives_and_affirmatives: affirmatives = negatives_and_affirmatives negatives = getblock(chunk, _vote_neg, 'So the amendment') else: affirmatives = getblock(chunk, _vote_aff, 'So the amendment') negatives = getblock(chunk, _vote_neg, 'So the amendment') if affirmatives: # Pop off the inclusive end block match line affs = affirmatives[1:len(affirmatives) - 1] affirmative_names = parse_vote_name_block(affs) if negatives: neg = negatives[1:len(negatives) - 1] negative_names = parse_vote_name_block(neg) log_args = ( str(bill_title) , len(affirmative_names) , len(negative_names) ) logger.info(" %s (amendment) - yays: %d, nays: %d" % log_args) return dict([ ('title', bill_title) , ('affirmatives', affirmative_names) , ('negatives', negative_names) , ('pass', _pass) , ('status_string', pass_status) , ('yays', len(affirmative_names)) , ('nays', len(negative_names)) # TODO: these will need to be adjusted to re-include the # removed ^L lines. , ('source_document_range', line_numbers) ])