Created
August 27, 2015 23:31
-
-
Save philcrump/f6ce51d1435d783079e8 to your computer and use it in GitHub Desktop.
FlightRadar24 Stats => CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import urllib.request | |
import json | |
import datetime | |
import csv | |
url='' | |
req = urllib.request.Request(url,headers={'User-Agent' : "Magic Browser"}) | |
response = urllib.request.urlopen(req) | |
jsonp = str(response.read()) | |
jsond = jsonp[ jsonp.index("(") + 1 : jsonp.rindex(")") ] | |
data = json.loads(jsond) | |
daysnames = [] | |
for daydata in data['days']: | |
daysnames.append(daydata) | |
filename = 'fr24-data-'+sorted(daysnames)[-1]+'.csv' | |
with open(filename, 'wt') as csvfile: | |
csvwriter = csv.writer(csvfile,delimiter=',',quotechar='"',quoting=csv.QUOTE_MINIMAL) | |
csvwriter.writerow(['Time','Hits','Positions']) | |
for dayname in sorted(daysnames): | |
pdate = datetime.datetime.strptime(dayname, '%Y%m%d') | |
print(pdate.isoformat()) | |
for q_stats in data['days'][dayname]['15min_stats']: | |
csvwriter.writerow([pdate.isoformat(),q_stats[0],q_stats[1]]) | |
pdate += datetime.timedelta(minutes=15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment