To run the script, cd into the appropriate directory and run
python GeoGrapher.py 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|
|direction (from nearest coast||Direction|
|(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.
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.