Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def get_last_100_year_data():
  2.     for year in range(1919, 2019):
  3.         url = "https://earthquake.usgs.gov/fdsnws/event/1/" \
  4.               "query?format=geojson&starttime={}-01-01&endtime={}-12-31&minmagnitude=3".format(year, year)
  5.         try:
  6.             response = requests.get(url)
  7.         except requests.ConnectionError or requests.HTTPError:
  8.             print('Error while contacting {}'.format(url))
  9.             continue
  10.         features = response.json()['features']
  11.  
  12.         for feature in features:
  13.  
  14.             lat, lon, _ = feature['geometry']['coordinates']
  15.             magnitude = feature['properties']['mag']
  16.             epoch_time_milli = float(feature['properties']['time'])
  17.             datetime_object = datetime.fromtimestamp(epoch_time_milli/1000)
  18.             print(lat, lon, magnitude, str(datetime_object))
  19.  
  20. get_last_100_year_data()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement