import json

infile = open('eq_data_1_day_m1.json','r')
outfile = open('readable_eq_data.json', 'w')

#the json.load() function converts the data into a 
#format python can work with: in this case a giant dictionary.

eq_data = json.load(infile)

#the json.dump() function takes a json data object and a file object, and 
json.dump(eq_data, outfile, indent=4)

list_of_eqs = eq_data['features']
mags, lons, lats,hover_texts = [],[],[],[]
for eq in list_of_eqs:
    mag = eq['properties']['mag']
    lon = eq['geometry']['coordinates'][0]
    lat = eq['geometry']['coordinates'][1]
    hover_text = eq['properties']['place']
    mags.append(mag)
    lons.append(lon)
    lats.append(lat)
    hover_texts.append(hover_text)


print(mags[:10])
print(lons[:10])
print(lats[:10])

from plotly.graph_objs import Scattergeo, Layout
from plotly import offline

data = [
    {
        'type':'scattergeo',
        'lon':lons,
        'lat':lats,
        'text': hover_texts,
        'marker':{
            'size': [5*mag for mag in mags],
            'color': mags,
            'colorscale': "Viridis",
            'reversescale': True,
            'colorbar':{'title': 'Magnitude'},
        }
    }
]
#trial to commit 

my_layout = Layout(title = "Global Earthquakers")

fig = {'data':data, 'layout':my_layout}

offline.plot(fig, filename= 'global_earthquakes.html')
