In [2]:
import pandas as pd, numpy as np

In [3]:
#load list of all circuits and years with races from wikipedia
df=pd.read_html('https://en.wikipedia.org/wiki/List_of_Formula_E_ePrix', header=0)

In [55]:
#geocode circuit names and create list with circuits
from pygeocoder import Geocoder
circs=[]
apikey='AIzaSyCWOe5ocJF-PMDJuVYFdp4tgB-pNjBv2hA'
for i in df.T.iteritems():
    circ={}
    circ['name']=i[1][0]
    z=i[1][1].replace('(','(').replace(')',')')
    circ['races']=z[z.find('(')+1:z.find(')')]
    circ['place']=z[:z.find('(')-7]
    circ['place']=circ['place'].replace(' ePri','')
    circ['coord']=Geocoder(apikey).geocode(circ['place']).coordinates
    circs.append(circ)
    print(circs[-1])


{'name': 'Autódromo Hermanos Rodríguez', 'races': '2016–2018', 'place': 'Mexico City', 'coord': (19.4326077, -99.133208)}
{'name': 'Battersea Park Street Circuit', 'races': '2015–2016', 'place': 'London', 'coord': (51.5073509, -0.1277583)}
{'name': 'Beijing Olympic Green Circuit', 'races': '2014–2015', 'place': 'Beijing', 'coord': (39.90419989999999, 116.4073963)}
{'name': 'Biscayne Bay Street Circuit', 'races': '2015', 'place': 'Miami', 'coord': (25.7616798, -80.1917902)}
{'name': 'Brooklyn Street Circuit', 'races': '2017–2018', 'place': 'New York City', 'coord': (40.7127753, -74.0059728)}
{'name': 'Circuit de Monaco', 'races': '2015, 2017', 'place': 'Monaco', 'coord': (43.73841760000001, 7.424615799999999)}
{'name': 'Circuit des Invalides', 'races': '2016–2018', 'place': 'Paris', 'coord': (48.856614, 2.3522219)}
{'name': 'Circuit International Automobile Moulay El Hassan', 'races': '2016, 2018', 'place': 'Marrakesh', 'coord': (31.6294723, -7.981084500000001)}
{'name': "Circuto Cittadino dell'EUR", 'races': '2018', 'place': 'Rome', 'coord': (41.9027835, 12.4963655)}
{'name': 'Hong Kong Central Harbourfront Circuit', 'races': '2016–2017', 'place': 'Hong Kong', 'coord': (22.396428, 114.109497)}
{'name': 'Karl–Marx–Allee Circuit', 'races': '2016', 'place': 'Berlin', 'coord': (52.52000659999999, 13.404954)}
{'name': 'Long Beach Street Circuit', 'races': '2014–2015', 'place': 'Long Beach', 'coord': (33.7700504, -118.1937395)}
{'name': 'Moscow Street Circuit', 'races': '2015', 'place': 'Moscow', 'coord': (55.755826, 37.6172999)}
{'name': 'Puerto Madero Street Circuit', 'races': '2015–2017', 'place': 'Buenos Aires', 'coord': (-34.6036844, -58.3815591)}
{'name': 'Punta del Este Street Circuit', 'races': '2014–2015, 2018', 'place': 'Punta del Este', 'coord': (-34.9368789, -54.9281496)}
{'name': 'Putrajaya Street Circuit', 'races': '2014–2015', 'place': 'Putrajaya', 'coord': (2.926361, 101.696445)}
{'name': 'Santiago Street Circuit', 'races': '2018', 'place': 'Santiago', 'coord': (-33.4488897, -70.6692655)}
{'name': 'Tempelhof Airport Street Circuit', 'races': '2015, 2017–2018', 'place': 'Berlin', 'coord': (52.52000659999999, 13.404954)}
{'name': 'Montreal Street Circuit', 'races': '2017', 'place': 'Montreal', 'coord': (45.5016889, -73.567256)}
{'name': 'Zürich Street Circuit', 'races': '2018', 'place': 'Zürich', 'coord': (47.3768866, 8.541694)}

In [70]:
years=[int(j.strip()) for i in circs for j in i['races'].replace(u'\u2013', '-').replace(',', '-').split('-') ]

In [72]:
calendar={i:[] for i in range(min(years),max(years)+1)}
for i in range(len(circs)):
    for k in circs[i]['races'].replace(u'\u2013', '-').replace(" ", ",").replace(",,", ",").split(","):
        r=k.find('-')
        if r==-1:
            calendar[np.int(k)].append(i)
        else:
            for j in range(np.int(k[:r]),np.int(k[r+1:])+1):
                calendar[j].append(i)

In [75]:
#save data
import json
open('calendar_fe2018.json','w').write(json.dumps(calendar))
open('circs_fe2018.json','w').write(json.dumps(circs))


Out[75]:
2484