-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopcovid19.py
47 lines (40 loc) · 915 Bytes
/
stopcovid19.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 serial
import time
import requests
url = ''
txt = requests.get('https://www.stopcovid19.jp/data/covid19japan-trend.txt')
data = txt.text.split('\n')
print(data)
port = '/dev/tty.SLAB_USBtoUART'
ser = serial.Serial()
ser.port = port
ser.baudrate = 115200
ser.timeout = 1
ser.setDTR(False)
ser.open()
def locate(x, y):
ser.write(b'\x15')
ser.write(chr(32 + x).encode())
ser.write(chr(32 + y).encode())
ser.write(b'\x13\x0c')
locate(2, 2)
ser.write(b'COVID19 ')
for i in range(1, int(data[0]), 3):
print(i, data[i])
pref = data[i].encode()
cur = data[i + 1].encode()
dcur = data[i + 2]
if (not dcur.startswith('-') and not dcur == '0'):
dcur = '+' + dcur
dcur = dcur.rjust(4, ' ')
dcur = dcur.encode()
n = i // 3 + 2
div = 7
x = n % div * 4 + 2
y = n // div * 3 + 2
locate(x, y)
ser.write(pref)
locate(x - 1, y + 1)
ser.write(dcur)
time.sleep(0.5)
ser.close()