I am new to python or JSON. I do a request to an API, can reach the data and print all the data that I need. The problem is : I print only one element, i would like to print all the loop.
import json
from urllib.request import urlopen
with urlopen("myapiurl") as response: source = response.read()
data = json.loads(source)
for item in data ["resultsPage"]["results"]["calendarEntry"]:
artistname = item["event"]["displayName"]
hour = item["event"]["start"]["time"]
day = item["event"]["start"]["date"]
oid = item["event"]["id"]
venue = item["event"]["venue"]["displayName"]
newJson = (
{oid:{
'artist': artistname,
'hour': hour,
'day': day,
'location': venue,
'description': "",
'expires': 1,}
})
with open('concert.json', 'w') as json_file:
json.dump(newJson, json_file, sort_keys=True, indent=2)
Let me know if you need the api url. Thanks !