-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_site.py
258 lines (229 loc) · 8.07 KB
/
gen_site.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/python
import sqlite3
import time
# TODO: bring into config file
# TODO: mercy tab icon
num_rows = 21
heroes = dict(zip('Bastion DVa Genji Hanzo Junkrat Lucio Mccree Mei Mercy Pharah Reaper Reinhardt Roadhog Soldier76 Symmetra Torbjorn Tracer Widowmaker Winston Zarya Zenyatta'.split(), [0] * 21))
css_lookup = dict(zip('DVa Symmetra Mercy Mei Lucio Winston Junkrat Roadhog Zarya Reaper Soldier76 Tracer Pharah Genji Reinhardt Mccree Widowmaker Bastion Zenyatta Torbjorn Hanzo'.split(),
'R19 R10 R13 R18 R15 R06 R17 R16 R08 R05 R02 R14 R07 R20 R09 R04 R01 R11 R00 R03 R12'.split()))
flair_width = 50;
flair_height = 45;
flair_coords = zip('Bastion DVa Genji Hanzo Junkrat Lucio Mccree Mei Mercy Pharah Reaper Reinhardt Roadhog Soldier76 Symmetra Torbjorn Tracer Widowmaker Winston Zarya Zenyatta default'.split(),
[
[1, 11], [1, 19], [1, 20], [1, 12], [1, 17], [1, 15], [1, 4], [1, 18], [1, 13], [1, 7], [1, 5], [1, 9], [1, 16], [1, 2], [1, 10], [1, 3], [1, 14], [1, 1], [1, 6], [1, 8], [1, 0], [0, 0]
])
flair_css = ''
for flair_name, (x, y) in flair_coords:
x_coord = x * flair_width * -1
y_coord = y * flair_height * -1
if (flair_name == 'default'):
x_coord = -2
y_coord = -2
flair_css = flair_css + '''
#{}_flair {{
width: {}px;
height: {}px;
background: url('./assets/flair_sprites.png') {}px {}px;
margin-right: 1em;
}}
'''.format(flair_name, flair_width, flair_height, x_coord, y_coord)
def print_start():
total_flaired = conn.execute("select count(1) from user where flair_id != 1").fetchone()[0]
total_users = conn.execute("select count(1) from user").fetchone()[0]
html_file.write('''<!DOCTYPE html>
<html>
<head>
<title>Overwatch Flair</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="./assets/refresh.js"></script>
</head>
<style>
body {
background-color: darkgrey;
font-family: 'Lucida Console', Monaco, monospace;
font-weight: bold;
}
h5 {
color: #eee;
}
h4 {color: darkgrey}
h3 {text-align: center;}
.scoreboard {
background-color: lightgrey;
border-radius: 25px;
border: 1px solid GoldenRod;
}
table { border-collapse: separate}
tr:first-child td:first-child { border-top-left-radius: 10px; }
tr:first-child td:last-child { border-top-right-radius: 10px; }
tr:last-child td:first-child { border-bottom-left-radius: 10px; }
tr:last-child td:last-child { border-bottom-right-radius: 10px; }
.ticker {
background-color: lightgrey;
border-radius: 25px;
border: 1px solid GoldenRod;
}
.logo {
max-height: 50%;
max-width: 50%;
}
.jumbotron {
border: 2px solid SlateGrey;
margin-top: 5px;
margin-bottom: 15px;
padding: 5px;
}
a {
color: royalblue;
}
a:hover {
color: goldenrod;
}
a:visited{ text-decoration: none;}
a:active { text-decoration: none;}
.user_counts{ }
''' + flair_css +
'''
</style>
<div class='container'>
<div class='jumbotron'>
<div class='table-responsive'>
<table>
<tr>
<td>
<a href='http://www.reddit.com/r/overwatch'>
<img src='./assets/logo.png' class='img-responsive' alt='Overwatch Logo' class='logo' height='50%' width='50%'>
</a>
</td>
<td style='white-space:nowrap'>
<a href='http://www.reddit.com/r/overwatch'><h2>/r/Overwatch Flair</h2></a>
</td>
<td style='white-space:nowrap; padding-left: 2em; padding-top: 1em;' class='user_counts'>
<h4>( refreshes automatically )</h4>
<table>
<tr>
<td>
[ <font color='DarkGreen'>{0:<6} </font> / <font color='DarkRed'> {1:<6} </font> ] - ( <font color='GoldenRod'>{2:>3.2f}%</font> ) users flaired
</td>
</tr>
</table>
</td>
<td style='padding-left:1em;'>
<h5>cobbled together by /u/mschock</h5>
</td>
</tr></table>
</div>
</div>
'''.format(total_flaired, total_users, (total_flaired / float(total_users)) * 100))
def print_end():
html_file.write("</div></div><br></body></html>")
def print_color(color, text):
html_file.write("<tr><font color='{0}'>{1}</font></tr>".format(color, text))
def print_ticker():
ticks = conn.execute("select a.user, b.name, c.name from ticker2 a join flair b on b.id = a.flair_id left join flair c on c.id = a.prev_id order by a.id desc limit {}".format(num_rows)).fetchall()
html_file.write('''
<div class='col-xs-6 ticker'>
<div class='table-responsive'>
<h3 class='sub-header'>Ticker</h3>
<table class='table table-striped'>
<tr>
<th>Type</th>
<th>User</th>
<th>From</th>
<th></th>
<th>To</th>
</tr>
''')
for user, flair_to, flair_from in ticks:
if flair_from is not None:
flair_from = get_name(flair_from)
flair_to = get_name(flair_to)
tick_type = 'UPD'
tick_color = 'DarkOrange'
if flair_from is None and flair_to == 'default':
tick_type = 'NEW'
tick_color = 'Green'
elif flair_to != 'default' and flair_from is None:
tick_type = 'NEW'
tick_color = 'RoyalBlue'
elif flair_from == flair_to:
tick_type = 'UPD'
tick_color = 'Sienna'
elif flair_to != 'default':
tick_type = 'UPD'
tick_color = 'FireBrick'
html_file.write('''
<tr style='color:{}'>
<td style='padding-top: 1.5em;' valign='middle' align='center'>[{}]</td>
<td style='padding-top: 1.5em;' valign='middle' align='left'>{}</td>
{}</td>
<td style='padding-top: 1.5em;' valign='middle' align='center'>>></td>
<td><img id='{}_flair' style='border: 2px solid {};border-radius: 5px;background-color: #e6e6e6;' src='./assets/img_trans.gif'></td>
</tr>
'''.format(tick_color, tick_type, user, ("<td style='padding-left: 2.5em;'><img id='{}_flair' style='border: 2px solid {};border-radius: 5px;;background-color: #e6e6e6;' src='./assets/img_trans.gif'>".format(flair_from, tick_color) if flair_from else "<td style='padding-top: 1.5em;' valign='middle' align='center'>None"), flair_to, tick_color))
html_file.write("</table></div></div>")
def print_scoreboard():
scores = conn_scoreboard.execute("select rank, name, count, percent, change, shift from scoreboard order by rank asc").fetchall()
html_file.write('''
<div class='col-xs-6 scoreboard'>
<div class='table-responsive'>
<h3 class='sub-header'>Scoreboard</h3>
<table class='table table-striped'>
<tr>
<th>Rank</th>
<th>Hero</th>
<th>Count</th>
<th>Percent</th>
<th>Change</th>
<th></th>
</tr>
''')
for rank, name, count, percent, change, shift in scores:
score_color = 'FireBrick'
if rank <= 5:
score_color = 'Green'
elif rank <= 10:
score_color = 'RoyalBlue'
elif rank <= 15:
score_color = 'Sienna'
shift_text = ''
if shift == 1:
shift_text = '+++'
elif shift == -1:
shift_text = '---'
if change >= 0:
change = '+' + str(change)
html_file.write('''
<tr style='color:{}'>
<td style='padding-top: 1.5em;' valign='middle' align='center'>[{}]</td>
<td><img id='{}_flair' style='border: 2px solid {};border-radius: 5px;background-color: #e6e6e6;' src='./assets/img_trans.gif'>{}</td>
<td style='padding-top: 1.5em;' valign='middle' align='center'>{}</td>
<td style='padding-top: 1.5em;' valign='middle' align='center'>{}%</td>
<td style='padding-top: 1.5em;' valign='middle' align='center'>{}</td>
<td style='padding-top: 1.5em;' valign='middle' align='center'>{}</td>
</tr>
'''.format(score_color, rank, name, score_color, name, count, percent, change, shift_text))
html_file.write("</table></div></div>")
def get_name(css):
for hero in heroes:
if hero in css or css_lookup[hero] in css:
return hero
return "default"
conn = sqlite3.connect('overwatch.db')
conn_scoreboard = sqlite3.connect('overwatch-scoreboard.db')
while True:
html_file = open('index.html', 'w')
print_start()
# insert ticker
print_ticker()
# insert scoreboard
print_scoreboard()
print_end()
html_file.close()
print("static page regenerated, sleeping 5 seconds...")
time.sleep(5)