-
Notifications
You must be signed in to change notification settings - Fork 0
/
npb.py
88 lines (82 loc) · 2.26 KB
/
npb.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
import os
import sys
import urllib.request
import datetime
from bs4 import BeautifulSoup
from vfd import VFD
from vfdimg import vfdimg
import time
class TeamInfo:
def __init__(self):
self.team = ''
self.score = ''
self.name = ''
class VsResult:
def __init__(self):
self.teams = []
self.teams.append(TeamInfo())
self.teams.append(TeamInfo())
args = sys.argv
if len(args) == 2:
str_day = args[1]
else:
today = datetime.date.today()
str_day = "{0:%Y%m%d}".format(today)
print(str_day)
url = 'https://baseball.yahoo.co.jp/npb/schedule/?date=' + str_day
response = urllib.request.urlopen(url)
data = response.read()
decoded_data = data.decode('utf_8')
#decoded_data = open('test.html').read() # for test
soup = BeautifulSoup(decoded_data, 'html.parser')
tables = soup.findAll('table', class_ = 'teams')
results = []
for table in tables:
result = VsResult()
scores = table.findAll('td', class_ = 'score_r')
teams = table.findAll('th', class_ = 'bt bb bl')
for i in [0 ,1]:
result.teams[i].score = scores[i].text
result.teams[i].team = teams[i].find('a')['data-ylk'][9:12] # slk:icon_XXX;pos:0
result.teams[i].name = teams[i].find('a')['title']
results.append(result)
vfd = VFD(17, 27)
vfd.open('/dev/ttyAMA0')
vfd.fontxy(2, 2)
for result in results:
t1 = result.teams[0]
t2 = result.teams[1]
print(t1.name + ' ' + t1.team + ' ' + t1.score
+ ' - ' + t2.score + ' ' + t2.team + ' ' + t2.name)
dir = os.path.dirname(__file__)
if dir != '':
dir = dir + '/'
dir = dir + 'icon/'
icon1 = vfdimg(dir + t1.team + '.bmp')
icon2 = vfdimg(dir + t2.team + '.bmp')
x = 280
vfd.cursor(x, 0)
vfd.drawimg(icon1)
x += 16 + 4
vfd.cursor(x, 0)
s = t1.score + ' - ' + t2.score
vfd.puts(s)
x += len(s) * 7 * 2 + 4
vfd.cursor(x, 0)
vfd.drawimg(icon2)
x += 16 + 20
vfd.cursor(x, 0)
vfd.scroll(2, 512, 1)
vfd.clr()
time.sleep(5)
vfd.fontxy(1, 1)
pos = [(0,0), (95,0), (190,0), (0,1), (95, 1), (190,1)]
i = 0
for result in results:
vfd.cursor(pos[i][0], pos[i][1])
t1 = result.teams[0]
t2 = result.teams[1]
s = t1.team + ' ' + t1.score + '-' + t2.score + ' ' + t2.team
vfd.puts(s)
i += 1
vfd.close()