EarthQuake Data

EARTHQUAKE DATA

This assignment is to use a combination of two APIs to collect and store realtime earthquake
data. The United States Geological Survey (USGS) maintains a public JSON API with information
on all earthquakes affecting the United States in the past hour, located at
https://earthquake.usgs.gov/earthquakes/feed/v1.0/…. The
information for each earthquake is embedded within a JSON array. The information of interest
for each earthquake is:

 Earthquake magnitude, which measures the relative size of the earthquake. The “mag”
field contains the earthquake magnitude.

 Earthquake coordinates, which indicate the geographic position of the earthquake. The
coordinates” field contains the longitude, latitude, and elevation of each earthquake.
Elevation is not relevant to this assignment, but record the longitude and latitude.

 Earthquake time, which indicates when the earthquake occurred. The “time” field
contains the earthquake time. The “time” field is stored in Unix epoch time format,
which measures time as the number of milliseconds since January 1, 1970. This format
can be converted to a humaninterpretable format as follows:
# Unix epoch time on September 1, 2022
orig_time = 1662015600000

# Convert milliseconds to seconds
orig_time_sec = orig_time / 1000

# Convert Unix epoch time to datetime object
import datetime
datetime_timestamp = datetime.datetime.utcfromtimestamp(orig_time_sec)

# Subtract 7 hours to adjust for time zone difference
datetime_adj_timestamp = datetime_timestamp  datetime.timedelta(hours = 7)

# Convert to humaninterpretable string
# String would say: “September 01, 2022 at 12:00:00 AM”
time_str = datetime_adj_timestamp.strftime(“%B %d, %Y at %I:%M:%S %p”)

Next, use a second API to obtain more information about the location of each earthquake. The
OpenCage API provides a free service the converts from latitude and longitude coordinates to
county and state. To avoid the API being overloaded with too many requests, OpenCage
requires that each user sign up for their own unique “key” for their application. Signing up is
free, and each key entitles the user to 2,500 requests per day, which should be more than
enough for this assignment. It can sign up for a key here https://opencagedata.com/dashboard It must obtain the own API key.
After signing up, the API key can be found here.

After completing the OpenCage signup, it can obtain geographic data about each earthquake

location using “https://api.opencagedata.com/geocode/v1/xml?q=lat+long&key=yourkey”.
Replace lat in the URL with the latitude of your earthquake; replace long in the URL with the
longitude of your earthquake; and replace yourkey in the URL with your API key. The API will
return results in XML format. The information of interest for each earthquake is:

 The county corresponding to the latitude and longitude. The “county” field contains the
county.

 The state corresponding to the latitude and longitude. The “state” field contains the
state.

For each earthquake, show a printout that reflects the complete information you have
obtained; for example:
Magnitude 0.51 earthquake on September 20, 2021 at 06:33:18 AM and located at
(33.6101667, 116.7991667) in Riverside County, California.
Magnitude 1.71 earthquake on September 20, 2021 at 06:20:33 AM and located at
(33.307, 116.343) in San Diego County, California.

Occasionally, an earthquake will not correspond to a location in the United States because it
occurred in the Ocean off the coast of the United States. In these cases, the OpenCage API will
not return a “county” or “state” field. Handle the potential error in your code (tryexcept is a
good strategy) and instead show an appropriate printout; for example:
Magnitude 5.1 earthquake on September 20, 2021 at 06:12:03 AM and located at (
36.7685, 74.004) in the Ocean.

Finally, output the data for each earthquake to a CSV file named “earthquakes.csv”. The CSV file
should have columns for time, magnitude, latitude, longitude, county, and state. For example:

September 20, 2021 at 06:33:18 AM 0.51 33.6101667 -116.7991667 Riverside County California
September 20, 2021 at 06:20:33 AM 1.71 33.307 -116.343 San Diego County California
September 20, 2021 at 06:12:03 AM 5.1 -36.7685 -74.004 N/A N/A

Ensure that your program overwrites the output CSV file each time that it runs.

Some considerations as you write your code:

 Consider the possibility that, when attempting connection to each API, some connection
issue occurs (that is, a status code other than 200). Ensure that your code handles this
case and provides the user with a helpful printout if it does occur.

 Ensure that your output is crisp, professional, and wellformatted. For example, ensure
that you have used spaces appropriately and checked your spelling.

 Adding comments in your code is encouraged. You may decide how best to comment
your code. At minimum, please use a comment at the start of your code to describe its
basic functionality.

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more