forked from ab-anand/Automation-Bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
earthquake.py
47 lines (43 loc) · 1.59 KB
/
earthquake.py
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
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import time
import datetime
import requests
import json
from colorama import Fore, init
URL = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson"
UPDATES = []
def earthquake_print(data):
for i in data['features']:
if i['id'] not in UPDATES:
UPDATES.append(i['id'])
print('___________________________________________________________________________________________________')
print(i['properties']['title'], end=' MAG: ')
print(Fore.RED+str(i['properties']['mag']))
print('Location:', i['properties']['place'])
alert = i['properties']['alert']
if alert == 'green':
print(Fore.RED + 'Type: ' + i['properties']['type'], end=' ')
elif alert == 'yellow':
print(Fore.YELLOW + 'Type: ' + i['properties']['type'], end=' ')
else:
print(Fore.BLUE + 'Type: ' + i['properties']['type'], end=' ')
ms = i['properties']['time']
print(datetime.datetime.fromtimestamp(ms/1000.0))
print('INFO:', i['properties']['url'])
def get_earthquakes():
resp = requests.get(URL)
resp = json.loads(resp.text)
count = resp['metadata']['count']
if count != 0:
earthquake_print(resp)
else:
pass
if __name__ == '__main__':
init(autoreset=True)
if len(sys.argv) != 2:
print('Usage: earthquake.py [time in seconds]')
else:
seconds = int(sys.argv[1])
while True:
get_earthquakes()
time.sleep(seconds)