forked from julianbruegger/corona-display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
79 lines (62 loc) · 2.06 KB
/
display.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
from bs4 import BeautifulSoup
import Adafruit_CharLCD as LCD
import requests
import time
import math
# Insert your URL here
url_c = "https://corona.help/country/switzerland"
# Insert your Population here
population_c = "8570000"
cc = "CH"
population_w = "7770173166"
url_w ="https://corona.help/"
#Raspberry Pi configuration:
lcd_rs = 27 # Change this to pin 21 on older revision Raspberry Pi's
lcd_en = 22
lcd_d4 = 25
lcd_d5 = 24
lcd_d6 = 23
lcd_d7 = 18
lcd_red = 4
lcd_green = 17
lcd_blue = 7 # Pin 7 is CE1
# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2
# Initialize the LCD using the pins above.
lcd = LCD.Adafruit_RGBCharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
lcd_columns, lcd_rows, lcd_red, lcd_green, lcd_blue)
while True:
page_c = requests.get(url_c)
soup_c = BeautifulSoup(page_c.text, 'html.parser')
page_w = requests.get(url_w)
soup_w = BeautifulSoup(page_w.text, 'html.parser')
# print (soup)
infections_c = soup_c.select('h1')[1].text.strip()
deaths_c = soup_c.select('h1')[2].text.strip()
survived_c = soup_c.select('h1')[3].text.strip()
infections_w = soup_w.select('h1')[1].text.strip()
deaths_w = soup_w.select('h1')[2].text.strip()
survived_w = soup_w.select('h1')[3].text.strip()
percent_c = '{:.7f}'.format(int(infections_c) / int(population_c))
percent_w = '{:.7f}'.format(int(infections_w) / int(population_w))
lcd.set_color(1.0, 0.54, 0.0)
lcd.clear()
lcd.message(cc + ' Cases ' + infections_c)
lcd.message('\nWW Cases ' + infections_w)
time.sleep(20.0)
lcd.set_color(0.0, 1.0, 0.0)
lcd.clear()
lcd.message(cc + ' Recoverd ' + survived_c)
lcd.message('\nWW ' + survived_w)
time.sleep(20.0)
lcd.set_color(1.0, 0.0, 0.0)
lcd.clear()
lcd.message(cc +' Dead ' + deaths_c)
lcd.message('\nWW Dead ' + deaths_w)
time.sleep(20.0)
lcd.set_color(0.2, 0.5, 0.4)
lcd.clear()
lcd.message('% of Swiss Population')
lcd.message('\n' + percent_w + '%')
time.sleep(20.0)