-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-html.py
79 lines (64 loc) · 3.52 KB
/
generate-html.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
import mysql.connector as mariadb
import time
import os
try:
saftb_db_host = os.environ["saftb_db_host"]
saftb_db_user = os.environ["saftb_db_user"]
saftb_db_password = os.environ["saftb_db_password"]
saftb_db_database = os.environ["saftb_db_database"]
except KeyError:
print("Please set the required environment variables")
exit(1)
mariadb_connection = mariadb.connect(host=saftb_db_host, user=saftb_db_user, password=saftb_db_password, database=saftb_db_database)
cursor = mariadb_connection.cursor()
#get all pickers
try:
cursor.execute("SELECT id,team_name FROM pickers;")
except mariadb.Error as error:
print("Error: {}".format(error))
pickers = cursor.fetchall()
scores = {}
for id, team_name in pickers:
scores[team_name] = []
try:
cursor.execute("select short_name, points from picks inner join api_teams t on (picks.team_id=t.id) inner join api_standings s on (t.api_id=s.team_api_id) where picks.season_id = 1 and pickers_id = %(pickers_id)s order by pick_number;", { 'pickers_id': id})
except mariadb.Error as error:
print("Error: {}".format(error))
teams = cursor.fetchall()
for short_name, points in teams:
scores[team_name].append([short_name, points])
mariadb_connection.close()
points = {}
for row in scores:
sum = 0
for team in scores[row]:
sum += team[1]
points[row] = sum
print("""<html>
<head>
<title>SAFTB - EPL</title>
</head>
<body>
<table border="1">""")
print("<tr><th>Team</th><th>Pick 1</th><th>Pick 2</th><th>Pick 3</th><th>Pick 4</th><th>Pick 5</th><th>Points</th></tr>")
for team in sorted(points, key=points.get, reverse=True):
print("<tr><td>{}</td><td>{} ({})</td><td>{} ({})</td><td>{} ({})</td><td>{} ({})</td><td>{} ({})</td><td>{}</td></tr>".format( team,
scores[team][0][0],
scores[team][0][1],
scores[team][1][0],
scores[team][1][1],
scores[team][2][0],
scores[team][2][1],
scores[team][3][0],
scores[team][3][1],
scores[team][4][0],
scores[team][4][1],
points[team]))
print("""</table>
</body>
<br />
<br />
<footer>
Last updated: {}
</footer>
</html>""".format(time.strftime("%Y-%m-%d %H:%M")))