Aug-21-2018, 01:31 PM
Hi, I was given a Python script from a vendor to pull down events from their API. The script works but I need to save these events to a file and not just view them. I'm not that familiar with Python but have a general understanding of programming. When I run the code below, it generates my text file but it only saves the last event pulled from the API and oddly saves two entries for it in the text file. In the code, I see a while loop and for loop and I think my json.dump command is inside both loops and therefore creating two entries in the text file. I've tried moving it outside each loop but not dice.
Any ideas would be appreciated!
Any ideas would be appreciated!
while True: data = export_events(token, event_type, batch_size, start_date, end_date, client_id, client_secret) total_events = total_events + len(data) if data is None: break elif len(data) == 0: break else: for event in data: with open('jsonfile.txt','w') as outfile: json.dump(data,outfile, indent=2, sort_keys=True) print json.dumps(data, indent=2, sort_keys=True)