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 )
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).
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
display_largest_magnitude_quake()
all_day.csv CSV file
on the USGS web site.