def gatherBillDetails(self, st): pv_dt = (datetime.datetime.today() - datetime.timedelta(int(config.default.prev_days))) logging.debug(str('Gathering Bills from %s forward: '%pv_dt.isoformat() + time.strftime("%B %d, %Y", time.gmtime()))) session = max([x for x in openstates.state_metadata(st)['session_details']]) bill_list = [x for x in openstates.bills(state=st, subjects='tax') if (x['updated_at'][:4]==str(datetime.date.today().year))] bill_list2 = [x for x in openstates.bills(state=st, q='tax') if (x['updated_at'][:4]==str(datetime.date.today().year)) and (x not in bill_list)] bill_list.extend(bill_list2) bills = [openstates.bill_detail(st, bill['session'], bill['bill_id']) for bill in bill_list] self.bill_lines = [] for bill in bills: if datetime.datetime.strptime(bill['updated_at'], '%Y-%m-%d %H:%M:%S') > pv_dt: insertrow = { 'ost_id' : bill['id'], 'div' : bill['bill_id'][:1], 'st' : bill['state'], 'session' : bill['session'], 'num' : bill['bill_id'].split()[1], 'details' : bill['title'], 'title': bill['title'], 'year': time.strftime('%Y'), 'webpage' : ", ".join([x['url'] for x in bill['sources']])[:149], 'subjects' : ", ".join(bill['subjects'])[:249], 'dateadd': datetime.datetime.now(), 'email': True, 'watched' : 'New' } self.bill_lines.append(insertrow) else: continue if len(self.bill_lines)<1: return False else: return session
def main(): detail = openstates.bill_detail(state="mn", session="upper", bill_id="SF 14") senate = openstates.bills(state="mn", chamber="upper", search_window="term") for bill in senate[:1]: print bill print bill.get("state") print bill.get("session") print bill.get("bill_id") detail = openstates.bill_detail( state=bill.get("state"), session=bill.get("session"), bill_id=bill.get("bill_id") ) print detail
def voteurl(id): """Calls to OpenStates API to grab bill URL""" bill = openstates.bill_detail(bill_id=id, state="pa", session="2011-2012") if bill['sources'][0]['url']: url = bill['sources'][0]['url'] else: url = None return url
def get_vote_url(bill_id_to_lookup): """Calls to OpenStates API to grab bill URL""" bill = openstates.bill_detail(bill_id=bill_id_to_lookup, state="pa", session="2011-2012") if bill['sources'][0]['url']: return bill['sources'][0]['url'] else: return None
def bills(bill_deet): form = RegistrationForm(request.form) bill_deets = Bill.query.filter_by(bill_name=bill_deet).first_or_404() # Get bills from Sunlight and add to database Bills table import sunlight import json from sunlight import openstates id_bill_json = openstates.bill_detail(state="id", session="%s" % bill_deets.year, bill_id="%s" % bill_deets.bill_id) return render_template("bills.html", bill_deet=bill_deet, user=current_user, id_bill_json=id_bill_json, form=form)
def ca_leg_text(legislationtext, caleg_id, firstname): q2_abill_insert = "" for line in legislationtext: data_legis = line.split(',') state = data_legis[0] session = data_legis[1] bill = data_legis[2] # print (state, session, bill) vote = openstates.bill_detail(state, session, bill) ## Get Legislation Role Value on Bill legislation_role = 0 role = "" for cs in vote['sponsors']: #print("Role TEST") if str(cs).find(caleg_id) != -1: if cs['type'] != 'other': legislation_role = legislation_role + 1 role = (cs['type']) if role == 'cosponsor': role = 'a cosponsor' if role == 'sponsor': role = 'a sponsor' if role == 'primary': role = 'an author' #print ("role" + str(bill)) ## Get Legislation Action Value on Bill legislation_action = 0 #print("Leg TEST") for cs in vote['votes']: #if str(cs).find(caleg_id) != -1: #print (str(cs['type'])) #legislation_action = legislation_action+1 if str(cs['yes_votes']).find(caleg_id) != -1: legislation_action = legislation_action + 1 if str(cs['no_votes']).find(caleg_id) != -1: legislation_action = legislation_action + 1 if str(cs['other_votes']).find(caleg_id) != -1: legislation_action = legislation_action + 1 # legislation_action = legislation_action-1 #print ("Leg action " + str(bill)) if legislation_action + legislation_role > 0: # The legislators votes #print (str((vote["bill_id"]).encode('utf-8'))) #print (str((vote['summary']).encode('utf-8'))) vote_url = "" vote_session = "" ##vote_url = vote['versions'] ##vote_url = vote_url[0] ##vote_url = vote_url['url'] ##vote_url = vote_url.replace("billNavClient", "billVotesClient") #CA LEG VOTE URL ABOVE INTERNAL BELOW #Example #vote_url = [[2015-2016 SB32 (USA CA)|SB 380]] vote_session = vote['session'] vote_session = str(vote_session[:4]) + "-" + str( vote_session[4:]) bill_link = vote_session + " " + bill.replace( " ", "") + " " + "(USA CA)" vote_url = bill_link + "|" + bill #print ("action/role: " + str(legislation_action) +"/" + str(legislation_role) + " " + str(bill)) ## Bill intro line q2_abill_insert += ( "\n\n'''" + "[[" + str(vote_url) + "]]" + " " + vote['title'] + "'''" ) # '''[http://ClimateCongress.us ClimateCongress.us]''' #print ("\n\n" + bill + ": " + vote['title']) #With description q2_abill_insert += ("\n\n'''" + bill + " " + vote['title'] + "'''"+ '\n\n' + "''" + str(vote['+impact_clause'])+ "''" ) # '''[http://ClimateCongress.us ClimateCongress.us]''' #print ("\n\n" + bill + ": " + vote['title']) ## Final Actions (Passed/Signed) if legislation_role > 0: q2_abill_insert += (str("\n\n" + firstname + " was " + role + " of " + bill + ".")) #print("Role added") for y in vote['actions']: if (y['type']) == ['amendment:passed']: #if y['+other_votes']: #q2_abill_insert += ("\n\nFinal legislative action " + (str(datetime.datetime.strptime(str(y['date']), '%Y-%m-%d %H:%M:%S').date())) + " passed yeas " + str(y['+yes_votes']).replace("'", "").replace("[", "").replace("]", "") + ", nays " + str(y['+no_votes']).replace("'", "").replace("[", "").replace("]", "") + " other " + str(y['+other_votes']).replace("'", "").replace("[", "").replace("]", "") +". " ) #else: q2_abill_insert += ( "\n\nFinal legislative action " + (str( datetime.datetime.strptime( str(y['date']), '%Y-%m-%d %H:%M:%S').date())) + " passed yeas " + str(y['+yes_votes']).replace( "'", "").replace("[", "").replace("]", "") + ", nays " + str(y['+no_votes']).replace("'", "").replace( "[", "").replace("]", "") + ". ") #print("yes") ##if (y['type']) == ['governor:signed']: ## q2_abill_insert += str("\n\n" + (str(datetime.datetime.strptime(str(y['date']), '%Y-%m-%d %H:%M:%S').date())) + " Governor signed" ) ## #print("yes") #http://leginfo.legislature.ca.gov/faces/billVotesClient.xhtml?bill_id=201520160SB32%20billVotesClient%20billNavClient for x in vote['votes']: if str(x).find( caleg_id) != -1: #print(str(x).find(caleg_id)) ##try: ## committee = str(x['committee']) ## pass ##except KeyError: ## committee = "Floor Action" ## pass ##q2_abill_insert += ("\n:*On " + str(str(datetime.datetime.strptime(str(x['date']), '%Y-%m-%d %H:%M:%S').date())) + " Committee: " + committee + " yeas " + str(x['yes_count']) + ", nays " + str(x['no_count']) + ". Passed: " + str(x['passed'])) #q2_abill_insert += ("\n:*On " + str(str(datetime.datetime.strptime(str(x['date']), '%Y-%m-%d %H:%M:%S').date())) + " yeas " + str(x['yes_count']) + ", nays " + str(x['no_count']) + ". Passed: " + str(x['passed'])) #print (str(x).encode('utf-8')) if str(x['yes_votes']).find(caleg_id) > 1: q2_abill_insert += ("\n:*" + firstname + " voted yea (in favor of " + str(x['motion']) + ").") #q2_abill_insert += ("\n:**On " + str(str(datetime.datetime.strptime(str(x['date']), '%Y-%m-%d %H:%M:%S').date())) + " " + firstname + " voted yea, in favor of the action: " + str(x['motion'])) if str(x['no_votes']).find(caleg_id) > 1: q2_abill_insert += ("\n:*" + firstname + " voted nay (against " + str(x['motion']) + ").") if str(x['other_votes']).find(caleg_id) > 1: q2_abill_insert += ( "\n:*" + firstname + " did not vote (abstain/not present on " + str(x['motion']) + ").") if q2_abill_insert.endswith('<!--EndQ2-->\n|'): return (q2_abill_insert) else: q2_abill_insert += "\n<!--EndQ2-->\n|\n" return (q2_abill_insert)
import commands """ Program to get the bill sponsor information and write it to db. """ author_db = pd.DataFrame(columns=['bill_name', 'sunlight_id', 'sponsor_name', 'sponsor_sunlight_id']) billdetail_db = pd.DataFrame(columns=['bill_name', 'sunlight_id', 'title', 'impact_clause', 'scraped_subjects', 'official_subjects', 'summary_sunlight', 'summary_text', 'full_cleaned_text']) ca_bills = openstates.bills(state='ca', search_window='term') authorindex = 0; billindex = 0; for i in range(len(ca_bills)): thisbilldetail = openstates.bill_detail(state='ca', session=ca_bills[i]['session'], bill_id = ca_bills[i]['bill_id']); keys = thisbilldetail.keys() if (thisbilldetail['created_at'] < '2015-06-01') and ('HR' not in thisbilldetail['bill_id']): billname = ca_bills[i]['bill_id']; billsid = ca_bills[i]['id']; billtitle = ca_bills[i]['title']; billclause = thisbilldetail['+impact_clause'] if 'scraped_subjects' in keys: billscraped = thisbilldetail['scraped_subjects'] else: billscraped = None; billofficial = thisbilldetail['subjects'] billsummarysun = thisbilldetail['summary'] billfilename = '/Users/sjcm/professional/insight/project/data_download/notebook/bills/' + billname.replace(" ", "") + '.html'
billdetail_db = pd.DataFrame(columns=[ 'bill_name', 'sunlight_id', 'title', 'impact_clause', 'scraped_subjects', 'official_subjects', 'summary_sunlight', 'summary_text', 'full_cleaned_text', 'session' ]) authorindex = 0 billindex = 0 for session in sessions: thissearch = 'session:' + session ca_bills = openstates.bills(state='ca', search_window=thissearch) for index, ca_bill in enumerate(ca_bills): print str(index) + 'out of ' + str(len(ca_bills)) thisbilldetail = openstates.bill_detail(state='ca', session=ca_bill['session'], bill_id=ca_bill['bill_id']) keys = thisbilldetail.keys() if 'HR' not in thisbilldetail['bill_id']: billname = ca_bill['bill_id'] billsid = ca_bill['id'] billtitle = ca_bill['title'] if '+impact_clause' in keys: billclause = thisbilldetail['+impact_clause'] else: billclause = None if 'scraped_subjects' in keys: billscraped = thisbilldetail['scraped_subjects'] else:
# create writer object on the file we named f # extrasaction parameter means that if there is a missing or extra leg_id in our array # then the writer will continue regardless writer = csv.DictWriter(f, fieldnames=ok_legislators_array, extrasaction='ignore') # write our header row with the legislators ids writer.writeheader() # loop through the bills from the previous api call for bill in oklahoma_bills: # get individual details on the bills, i.e. votes # see example output: http://sunlightlabs.github.io/openstates-api/bills.html#examples/bill-detail oklahoma_bill_details = openstates.bill_detail( state='ok', session='2015-2016', bill_id=bill['bill_id'] ) # loop through votes looking for the third reading for bill_votes in oklahoma_bill_details['votes']: # we're looking for 'third' either upper or lower case (upper in this instance, but might be odd ball) pattern = re.compile('third', re.IGNORECASE) # if the motion matches 'third' if pattern.search(bill_votes['motion']): total_votes = {} # bill id added as a reference column for each vote
def votes_for_bill(self, bill): return openstates.bill_detail(bill_id=bill.bill_id, state=bill.state, session=bill.session)['votes']
# Add Bill URLs to bill information # from sunlight import openstates import pprint from load_database import * bill_queryset = session.query(pa_bills).all() for (offset, bill) in enumerate(bill_queryset): if not offset % 50: print offset session.commit() openstates_data = openstates.bill_detail(bill_id=bill.bill_id, state="pa", session="2011-2012") if openstates_data['sources'][0]['url']: bill.bill_url = openstates_data['sources'][0]['url'] else: bill.bill_url = None session.add(bill) session.commit()
def get_bill_data(self, bill_name): return openstates.bill_detail('tx', '84', bill_name)
def detail(request, state, session, bill_id): bill = openstates.bill_detail(state=state, session=session, bill_id=bill_id) print(bill) return render(request, 'billtrack/detail.html', {'bill': bill})
#print(val) val = val.split(" ") state = str(val[3][:-2]).lower() #print(state) #session = str(val[0])[2:6]+str(val[0])[7:] #print(session) session = str(val[0])[1:5] + str(val[0])[6:] #print(session) bill = str(val[1])[:2] + " " + str(val[1])[2:] #print(bill) #print("Forming API query akin to URL query: openstates.org/api/v1/bills/ca/20152016/AB 1550/") delay = (1.72) sleep(delay) print("Query for: " + state + session + bill) # Input is expected to be formatted as ca20152016AB 197 vote = openstates.bill_detail(state, session, bill) #print(str(vote).encode('utf-8')) #print (bill) #print (vote['sponsors']) # for x in vote: page_start = "{{US CA Bill\n" new_c = page_start new_c += custom new_c += ("|Instance of=Bill") new_c += ("\n|Session=" + str(session[:4]) + "-" + str(session[4:])) new_c += ("\n|Bill=" + str(bill)) new_c += ("\n|Gov=USA CA") new_c += ("\n|Branch=Legislative") new_c += ("\n|OpenStateVoteID=" + vote['id']) new_c += ("\n|Bill page=" + str(vote['sources'][0])[9:-2]) new_c += ("\n|Vote page=" + str(vote['sources'][0]).replace(