I am requesting weather data via API requests for a given coordinate. One request allows me to get 10 days of data. I would like to make multiple requests in order to get historical data. I am unsure how to merge the requests into one JSON file.
At the moment, I'm creating a list of JSON requests. How do merge into one JSON?
import requests
import pyarrow as arrow
response_list=[]
for dates in dates:
start = arrow.get(dates)
response = requests.get(
'https://-URL',
params={
foo:bar
'start': start
'end': start.shift(days=10)
},
headers={
'Authorization': api_key
}
)
response_list.append(response.json())
# Do something with response data.
I get all the data in a list, but I want it all in 1 JSON object instead of a list of JSON objects.
Maybe this will help:
print("response 1 dates: ")
print(response_list[0]["meta"])
print("response all dates: ")
print(response_list["meta"])
Output:
response 1 dates:
{'cost': 1, 'dailyQuota': 50, 'end': '2019-10-26 00:00', 'lat': -8.848808, 'lng': 115.171059, 'params': ['swellDirection'], 'requestCount': 22, 'start': '2019-10-25 00:00'}
response all dates:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-83-6f4ff2d1a0b8> in <module>()
5
6 print("response all dates: ")
----> 7 print(response_list["meta"])
8
9
TypeError: list indices must be integers or slices, not str