Hands-Off USGS Webscraping of Earthquakes- Worldwide (24 Hours)

Featured image USGS Magnitude 2.5+ Earthquakes, Past Day.

Forbes: One out of three people in the world is exposed to earthquakes, a number which almost doubled in the past 40 years. On average earthquakes cause nearly US$40 billion in direct economic loss every year, by destroying production sites and disrupting transport lines. Knowing an area’s seismic hazard is now a bigger priority than ever.

Data resulting from seismic monitoring can be used to distinguish between an underground nuclear explosion and the numerous natural and man-made seismic events that occur every day, such as earthquakes and mining explosions. 

Using USGS earthquake data feed, we built a live earthquake tracker of global tremors as detected by monitoring stations worldwide (24 hours).

We set the working directory YOURPATH

import os
os.chdir(‘YOURPATH’)
os. getcwd()

and import the libraries

import urllib.request
import json
import re
import datetime
import matplotlib.pyplot as plt
import math

Let’s invoke the key function printResults

def printResults(data):

theJSON = json.loads(data)

if "title" in theJSON["metadata"]:
    print("\n" + re.sub('\, ','\n',theJSON["metadata"]["title"]) + "\n")


count = theJSON["metadata"]["count"]
print (str(count) + " events recorded\n")

georejestr = []

for element in theJSON["features"]:
    print ("Magnitude:", round(float(element["properties"]["mag"]),1), "Event time:", datetime.datetime.fromtimestamp(element["properties"]["time"] / 1000).strftime('%Y-%m-%d %H:%M:%S') , "  Epicenter:", end = '')
    if re.sub ("\D|\.|\s", "", element["properties"]["place"]) != "":
        print(" ", element["properties"]["place"])
    elif re.search ("Near", element["properties"]["place"]) != None:
        print(" ", element["properties"]["place"])
    else:
        print("  Under", element["properties"]["place"])
    print()    
    georejestr.append([element["geometry"]["coordinates"][0:2],element["properties"]["mag"],element["properties"]["time"]])

clr = ['fuchsia','deeppink','mediumvioletred','darkviolet','indigo','black','red']
im = plt.imread("https://www.freepngimg.com/thumb/earth/93077-world-area-map-free-png-hq.png")
implot = plt.imshow(im)
for coord,m,tran in georejestr:
    plt.scatter(x=(float(coord[0])+180)*2840/360, y=(-(float(coord[1]))+94)*1850/180, c=clr[math.ceil(m-3)], s=(int((m/1.5)**4)),  alpha=(round((datetime.datetime.now().timestamp()/3600-tran /1000/ 3600)/24,1)))
plt.savefig("plot.png")
plt.show()

and run the main() function

def main():
urlData = “http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson”

webUrl = urllib.request.urlopen(urlData)
print ("Connecting to US Geological Survey API.\n\nChecking connection... Result code: " + str(webUrl.getcode()), end ="")
if (webUrl.getcode() == 200):
    print (".\nIt's OK! Receiving data...")
    data = webUrl.read()
    printResults(data)
else:
    print("[EN] Received error, cannot parse results\n[PL] Wystąpił błąd, nie można użyć wyników")

if name == “main“:
main()

Connecting to US Geological Survey API.

Checking connection... Result code: 200.
It's OK! Receiving data...

USGS Magnitude 2.5+ Earthquakes
Past Day

46 events recorded

Magnitude: 5.3 Event time: 2022-11-11 15:31:52   Epicenter:  Under southern Mid-Atlantic Ridge

Magnitude: 5.0 Event time: 2022-11-11 13:34:46   Epicenter:  88 km SW of Tarauacá, Brazil

Magnitude: 2.8 Event time: 2022-11-11 13:05:35   Epicenter:  16km ESE of Little Lake, CA

Magnitude: 5.1 Event time: 2022-11-11 12:57:33   Epicenter:  228 km ENE of Neiafu, Tonga

Magnitude: 5.0 Event time: 2022-11-11 12:39:28   Epicenter:  191 km W of Bengkulu, Indonesia

Magnitude: 2.6 Event time: 2022-11-11 12:29:05   Epicenter:  45 km NNW of Valdez, Alaska

Magnitude: 3.2 Event time: 2022-11-11 12:16:19   Epicenter:  15km WSW of Searles Valley, CA

Magnitude: 4.9 Event time: 2022-11-11 12:01:49   Epicenter:  Under Vanuatu region

Magnitude: 7.3 Event time: 2022-11-11 11:48:45   Epicenter:  211 km ESE of Neiafu, Tonga

Magnitude: 2.5 Event time: 2022-11-11 11:21:44   Epicenter:  3 km SW of Peñuelas, Puerto Rico

Magnitude: 4.5 Event time: 2022-11-11 11:16:32   Epicenter:  148 km NE of Lospalos, Timor Leste

Magnitude: 3.1 Event time: 2022-11-11 10:30:36   Epicenter:  76 km N of Tierras Nuevas Poniente, Puerto Rico

Magnitude: 3.7 Event time: 2022-11-11 10:19:50   Epicenter:  12 km WNW of Petersville, Alaska

Magnitude: 4.4 Event time: 2022-11-11 08:25:17   Epicenter:  6 km WSW of Babushkin, Russia

Magnitude: 2.5 Event time: 2022-11-11 07:16:59   Epicenter:  8 km S of Manila, Arkansas

Magnitude: 3.2 Event time: 2022-11-11 07:09:30   Epicenter:  5 km SE of Tiptonville, Tennessee

Magnitude: 2.7 Event time: 2022-11-11 06:43:56   Epicenter:  27 km NNE of Pilot Point, Alaska

Magnitude: 3.1 Event time: 2022-11-11 06:08:41   Epicenter:  Under Puerto Rico region

Magnitude: 2.5 Event time: 2022-11-11 05:08:15   Epicenter:  20 km SW of Coyanosa, Texas

Magnitude: 2.7 Event time: 2022-11-11 04:54:53   Epicenter:  28 km S of Nanwalek, Alaska

Magnitude: 4.1 Event time: 2022-11-11 04:41:19   Epicenter:  52 km WSW of Tola, Nicaragua

Magnitude: 2.8 Event time: 2022-11-11 04:17:03   Epicenter:  1 km SW of Pāhala, Hawaii

Magnitude: 3.5 Event time: 2022-11-11 02:47:56   Epicenter:  99 km N of Cruz Bay, U.S. Virgin Islands

Magnitude: 4.9 Event time: 2022-11-11 02:36:57   Epicenter:  3 km E of Bungahan, Philippines

Magnitude: 4.2 Event time: 2022-11-11 02:32:15   Epicenter:  43 km SSW of Mawlaik, Myanmar

Magnitude: 2.7 Event time: 2022-11-11 02:19:23   Epicenter:  79 km N of Charlotte Amalie, U.S. Virgin Islands

Magnitude: 2.8 Event time: 2022-11-11 02:12:59   Epicenter:  1 km S of Garrochales, Puerto Rico

Magnitude: 4.5 Event time: 2022-11-11 02:04:06   Epicenter:  87 km S of Shikotan, Russia

Magnitude: 3.9 Event time: 2022-11-11 01:31:14   Epicenter:  67 km N of Cruz Bay, U.S. Virgin Islands

Magnitude: 2.7 Event time: 2022-11-11 01:26:22   Epicenter:  5 km WSW of Guánica, Puerto Rico

Magnitude: 2.9 Event time: 2022-11-11 00:25:49   Epicenter:  3 km ESE of Medicine Park, Oklahoma

Magnitude: 4.5 Event time: 2022-11-11 00:16:08   Epicenter:  16 km S of Magdalena, Philippines

Magnitude: 3.8 Event time: 2022-11-10 23:36:40   Epicenter:  30 km NNE of Pilot Point, Alaska

Magnitude: 3.4 Event time: 2022-11-10 23:36:23   Epicenter:  27 km NNE of Pilot Point, Alaska

Magnitude: 4.4 Event time: 2022-11-10 22:50:20   Epicenter:  Under south of the Fiji Islands

Magnitude: 3.3 Event time: 2022-11-10 22:36:00   Epicenter:  Under Virgin Islands

Magnitude: 2.7 Event time: 2022-11-10 20:20:04   Epicenter:  1 km ENE of Tanaina, Alaska

Magnitude: 4.5 Event time: 2022-11-10 19:58:15   Epicenter:  49 km WSW of Rabaul, Papua New Guinea

Magnitude: 2.5 Event time: 2022-11-10 19:37:09   Epicenter:  1 km NW of Magas Arriba, Puerto Rico

Magnitude: 3.9 Event time: 2022-11-10 19:34:24   Epicenter:  107 km N of Cruz Bay, U.S. Virgin Islands

Magnitude: 3.3 Event time: 2022-11-10 19:07:25   Epicenter:  3 km SSE of Pájaros, Puerto Rico

Magnitude: 4.3 Event time: 2022-11-10 18:58:48   Epicenter:  Under Banda Sea

Magnitude: 4.4 Event time: 2022-11-10 18:54:11   Epicenter:  26 km NE of Senigallia, Italy

Magnitude: 2.6 Event time: 2022-11-10 17:32:41   Epicenter:  60 km SSE of Hughes, Alaska

Magnitude: 3.1 Event time: 2022-11-10 17:32:19   Epicenter:  57 km SSW of Shungnak, Alaska

Magnitude: 4.4 Event time: 2022-11-10 16:05:43   Epicenter:  53 km S of Ust’-Kamchatsk Staryy, Russia
Earthquakes worldwide 24 hours

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: