'Loop that formats an API query based on key value in a list and then paginate through each one of those queries
I have a dictionary within a list of objects, and I'm trying to grab the value of the "state" key in this list. When I grab the value of the "state" key, I want to parse that key into an API query. When the API does the query, I want to paginate through those results, and then move on to the next "state" key. I just can't wrap my head around how I'd do this. Here's what I have so far.
api_url = api.taxes.info.net/taxes/%s/rate?page=1
list =[
{"state": "Ohio",
"state": "California",
"state": "Georgia"}
]
tax_rates = []
for i in list:
state = i.get("state") #grabs the value of the "state" key
r = requests.get(api_url % state) #pasrses the state into the url string format
pagination= r.links.get('next', {}).get('url') #api has link headers available that can go through
while pagination != None:
tax_rates.extend([item for item in response.json()])
print(tax_rates)
When I try to print the results in my list (tax_rates), I get an empty list. I'm not really confident in my coding ability, so I'm pretty sure there's some logic that I'm not putting together properly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
