State Bill Tracker
Introduction
Today, I developed a python program that extracts and tracks US state bills related to artificial intelligence using two different legislative APIs: LegiScan and OpenStates.
Development Notes
I started by downloading relevant librarys for API calls and dataframes.
pip install requests pandas openpyxl
For Legiscan, I created an account and requested an API key to pull the bills.
Using my API key and the base url, I made two methods to first get the states and the session ids since I need them to search the bills.
Then, I use both the states and session ids in my search_ai_bills method since Legiscan’s getBill documentation requries them as params. Additionally, I added “&query=artificial+intelligence” in the URL in order to only search for AI bills.
Have extracted the desired bills, I then get those bills’ details for the excel sheet.
Finally, in my main, I loop through each states and their bills to fetch desired bills and then create a dataframe using pandas to extract them to an excel file
I extraced 943 bills using Legiscan’s API
For OpenStates, I pretty much used the same framework to extract the bills.
First of all, I created an account to request an API key
Then I use the /jurisdiction root in my get_jurisdiction method to only find all states by adding a “state” classification to my url = f”{BASE_URL}/jurisdictions?classification=state”
With those jurisdictions, I used the /bills root with certian params to search for AI bills. Then, I loop through every AI bill I have and append more information about them for the excel file.
Lastly, I call on both methods in my main to extract the AI bills into an excel file using pandas
Issue: The abstract query isn’t working in my search_ai_bills method
OpenStates request limit: Due to this limit, I can only extract a few hundred bills at once