Coursework 3

Part C: Get earthquake data from the USGS website
and display today's largest magnitude quake

Preliminaries

For this part of the coursework you will be downloading and processing data about Earthquakes from the web. One way to access web pages or data stored on web pages in Python is by using the urllib module. This is illustrated by the following code sample, which downloads lines of text from a web page and prints them out. Try running the code and see what happens.
import urllib.request   # This module is used for getting data from a URL

def print_text_from_url( url ):
        url_data = urllib.request.urlopen(url)
        lines = url_data.readlines() # Read all lines into a list
        for line in lines:
                # Decode 'utf-8' string encoding and chop off newline:
                decoded_line = line.decode('utf-8')[0:-1]
                print( decoded_line )

LOREM_IPSUM_URL = "https://s3.eu-west-2.amazonaws.com/p4w-cw3-2017/lorem_ipsum.txt"
print_text_from_url( LOREM_IPSUM_URL )

USGS Earthquake Data

The US Geographical Society (USGS) publishes an online dataset of all earthquakes that happen across the world each day. This can be downloaded (in the form of a CSV file) from the following URL:

http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.csv

For this part of the coursework, you will first write a function to extract and display information from a pre-saved file of earthquake data (which I downloaded last year). You will then display similar information, but by first retrieving it from the USGS website (which is updated daily).

Functions you need to write

  1. [3 Marks]
    display_quake( quake_record )
    This function should take a quake record as its argument. A quake record is just a list of strings representing various measurements and features of the quake. Some example quake records can be seen in the starter file quake_web.py. The function should print out certain key data about the quake in a format similar to the following:
         Time:       2016-11-08T04:55:44.250Z
         Latitude:   -36.5806
         Longitude:  -73.6355
         Location:   48km WNW of Talcahuano, Chile
         Magnitude:  5.9
         Depth:      17.3
    

  2. [5 Marks]
    display_largest_magnitude_quake()
    This should display the quake record of the largest magnitude quake recorded on the current day, when the function is run. To do this you need to:

    Files Provided: