Skip to content
A short script that maps geographic attributes (earthquake affected, war, etc) to multiple countries/cities.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Photo by Andrew Neel on Unsplash

To run the script, cd into the appropriate directory and run python into the command line.

The script goes to the United States Geological Survey (USGS) website to retrieve the geo.json file of Significant Earthquakes in the past 30 days, parsing it using split() function to extract:

Colons can be used to align columns.

Extracted Data Notes To .csv
title Title
country Country
longitude Latitude
latitude Longitude
magnitude Magnitude
alert Alert
tsunami Tsunami
range Range
direction (from nearest coast Direction
Mag_max Country affected
(coming soon) City affected

The script will print the logs to the command line, just as a check for the content. Using the Shapely module and the countries.geo.json, a point is constructed from the extracted earthquake coordinates.

Comparing each earthquake, a for loop runs over each point and checks whether the point intersects or the country polygon. If this is true, then it prints the country that the earthquake has affected.

Finally, the writerow() function prints this information in a tabular format to Earthquakes.csv. Note that additional running of this script overwrites previous files with the same name. To change this instead append to existing file, change the following line:

w = csv.writer(open("Earthquakes.csv","w"))


w = csv.writer(open("Earthquakes.csv","a"))

"a" means append (add the data to the end of this file if it already exists), while "w" only writes.

You can’t perform that action at this time.