-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
99 lines (78 loc) · 2.65 KB
/
script.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import lcddriver
import time
import http.client
import json
import os
conn = http.client.HTTPSConnection("api.collectapi.com")
headers = {
'content-type': "application/json",
'authorization': "apikey collectapi-key"
}
conn.request("GET", "/corona/totalData", headers=headers)
res = conn.getresponse()
data = res.read()
decoded = data.decode("utf-8")
new_data = json.loads(decoded)
totalCases = new_data['result']['totalCases']
totalDeaths = new_data['result']['totalDeaths']
totalRecovered = new_data['result']['totalRecovered']
conn = http.client.HTTPSConnection("api.collectapi.com")
headers = {
'content-type': "application/json",
'authorization': "apikey 0m5BDVJjfn7JPxMZS5azuV:7JebP4KUwsdvUCtRaqq06e"
}
conn.request("GET", "/corona/countriesData", headers=headers)
res = conn.getresponse()
data = res.read()
decoded = data.decode("utf-8")
new_data = json.loads(decoded)
turnCount = 0
def foo(json_object, country):
for dict in json_object:
if dict['country'] == country:
return dict['totalCases']
def long_string(display, text = '', num_line = 1, num_cols = 16):
if(len(text) > num_cols):
display.lcd_display_string(text[:num_cols],num_line)
time.sleep(1)
for i in range(len(text) - num_cols + 1):
text_to_print = text[i:i+num_cols]
display.lcd_display_string(text_to_print,num_line)
time.sleep(0.2)
time.sleep(1)
else:
display.lcd_display_string(text,num_line)
totalCasesTurkey = foo(new_data['result'], 'Turkey')
display = lcddriver.lcd()
try:
while True:
display.lcd_display_string("COVID-19 Cases", 1)
time.sleep(2)
display.lcd_clear()
time.sleep(2)
display.lcd_display_string("Worldwide", 1)
display.lcd_display_string("C: %s" % totalCases, 2)
time.sleep(3)
display.lcd_display_string("D: %s" % totalDeaths, 2)
time.sleep(3)
display.lcd_display_string("R: %s" % totalRecovered, 2)
time.sleep(2)
display.lcd_clear()
time.sleep(2)
for obj in new_data['result']:
long_string(display, obj['country'], 1)
display.lcd_display_string("C: %s" % obj['totalCases'], 2)
time.sleep(3)
display.lcd_display_string("D: %s" % obj['totalDeaths'], 2)
time.sleep(3)
display.lcd_display_string("R: %s" % obj['totalRecovered'], 2)
time.sleep(3)
display.lcd_clear()
time.sleep(2)
turnCount += 1
if(turnCount >= 2):
break
except KeyboardInterrupt:
print("Cleaning up!")
display.lcd_clear()
os.system("python3 cor.py")