-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyQuake.py
More file actions
35 lines (29 loc) · 923 Bytes
/
PyQuake.py
File metadata and controls
35 lines (29 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
import json
import sys
# The url you provided
url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson"
# Command line options
simple = False
for arg in sys.argv:
if arg == "/s":
simple = True
# Get the contents of the URL
response = requests.get(url)
# Check for errors
if response.status_code != 200:
print(f"Error: {response.status_code}")
else:
# Parse the JSON data
data = response.json()
# Print the results in a more readable format
print("Earthquakes Summary:\n")
print("-" * 20)
for feature in data['features']:
properties = feature['properties']
if not simple:
print(f"Magnitude: {properties['mag']}")
print(f"Location: {properties['place']}")
print(f"URL: {properties['url']}\n")
else:
print(f"{properties['title']}\n")