Earthquake Data API

Earthquake Data provided by USGS.gov is very neat and complete. You can arrange your query based on parameters like coordinates, dates, alert level, tsunami causing or not, duration and others.

If you are interested in earthquake data, this is certainly an API you should check out.

Here is a simple example about how you can make use of USGS.gov‘s earthquake API.


import requests
import json

def earthquake(f):
    paramss = {"format": "geojson", "starttime": "2018- 
    01-01", "endtime": "2019-12-31", "alertlevel": 
    "orange"}
    data = requests.get(f, params = paramss)
    data = json.loads(data.text)
    return data

f = r"https://earthquake.usgs.gov/fdsnws/event/1/query?"
a = earthquake(f)

for i in (a["features"]):
    print(i["properties"]["time"], i["properties"]["place"], 
    i["properties"]["cdi"], i["properties"]["tsunami"])
timeplacecountrymagnitudetsunami
157473685259416km WSW of Mamurras,Albania9.10
157316682542857km NE of Hashtrud,Iran7.90
15693229149698km SSE of New MirpurPakistan7.10
156121379614811km SE of Xunchang,China5.80
155885647507378km SE of Lagunas,Peru8.91
154794797248010km SSW of Coquimbo,Chile7.81
154359896933014km NNW of Anchorage,Alaska7.61
153617087915027km ENE of Tomakomai,Japan8.11
15334695986300km SW of Loloan,Indonesia8.11

If you need a refresher on user defined functions lesson in Python here is a link to our Defining Functions Lesson.

Source of API: Earthquake USGS

Source: The Seattle Times

Recommended Posts