-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebsite_info.py
225 lines (184 loc) · 4.53 KB
/
website_info.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
# This file has all the helper bits to make the website
# A piece of code that will cause the website to auto-refresh
def autorefresh_str(my_ip_addr):
script_str = "<script>setInterval(function(){window.open('http://" + my_ip_addr + "', \"_self\")}, 3000);</script>"
return script_str
# Function to return a piece of HTMl for the bar chart
def createBar(tick_count, day_of_week):
# From the number of ticks, calculate the liters
liters_used = tick_count * 0.06565217391
# From the liters, calculate the percent of 600 L
percent_used = int(liters_used / 600.0 * 100.0)
if day_of_week == 0:
day = "Monday"
elif day_of_week == 1:
day = "Tuesday"
elif day_of_week == 2:
day = "Wednesday"
elif day_of_week == 3:
day = "Thursday"
elif day_of_week == 4:
day = "Friday"
elif day_of_week == 5:
day = "Saturday"
elif day_of_week == 6:
day = "Sunday"
# Create the HTML code snippet
if liters_used > 600:
html_code = "<tr style=\"height:" + str(percent_used) + "%\"><th scope=\"row\">" + day + "</th><td><span><span class=\"blink_me\"><b><i>" + str(int(liters_used)) + " L</span></span></td>"
else:
html_code = "<tr style=\"height:" + str(percent_used) + "%\"><th scope=\"row\">" + day + "</th><td><span>" + str(int(liters_used)) + " L</span></td>"
return html_code
# HTML and CSS starting code
html_start = """<html>
<head>
<style>
/* Reference for blinking text */
/* https://stackoverflow.com/questions/16344354/how-to-make-blinking-flashing-text-with-css-3 */
.blink_me {
animation: blinker 1s linear infinite;
}
@keyframes blinker {
50% { opacity: 0; }
}
/* Reference for bar chart */
/* https://codepen.io/inegoita/pen/YMrJGY */
body, table, input, select, textarea {
}
.graph {
margin-bottom:1em;
font:normal 100%/150% arial,helvetica,sans-serif;
}
.graph caption {
font:bold 150%/120% arial,helvetica,sans-serif;
padding-bottom:0.33em;
}
.graph tbody th {
text-align:right;
}
@supports (display:grid) {
@media (min-width:32em) {
.graph {
display:block;
width:600px;
height:300px;
}
.graph caption {
display:block;
}
.graph thead {
display:none;
}
.graph tbody {
position:relative;
display:grid;
grid-template-columns:repeat(auto-fit, minmax(2em, 1fr));
column-gap:2.5%;
align-items:end;
height:100%;
margin:3em 0 1em 2.8em;
padding:0 1em;
border-bottom:2px solid rgba(0,0,0,0.5);
background:repeating-linear-gradient(
180deg,
rgba(170,170,170,0.7) 0,
rgba(170,170,170,0.7) 1px,
transparent 1px,
transparent 20%
);
}
.graph tbody:before,
.graph tbody:after {
position:absolute;
left:-3.2em;
width:2.8em;
text-align:right;
font:bold 80%/120% arial,helvetica,sans-serif;
}
.graph tbody:before {
content:"600 L"; /* Top of the graph, 100%, gets a label of 600 L */
top:-0.6em;
}
.graph tbody:after {
content:"0 L"; /* Bottom of the graph, 0%, gets a label of 0 L */
bottom:-0.6em;
}
.graph tr {
position:relative;
display:block;
}
.graph tr:hover {
z-index:999;
}
.graph th,
.graph td {
display:block;
text-align:center;
}
.graph tbody th {
position:absolute;
top:-3em;
left:0;
width:100%;
font-weight:normal;
text-align:center;
white-space:nowrap;
text-indent:0;
transform:rotate(-45deg);
}
.graph tbody th:after {
content:"";
}
.graph td {
width:100%;
height:100%;
background:rgba(104, 220, 238, 0.8); /* Colour of the vertical bars */
border-radius:0.5em 0.5em 0 0;
transition:background 0.5s;
}
.graph tr:hover td {
opacity:0.7;
}
.graph td span {
overflow:hidden;
position:absolute;
left:50%;
top:50%;
width:0;
padding:0.5em 0;
margin:-1em 0 0;
font:normal 85%/120% arial,helvetica,sans-serif;
font-weight:bold;
opacity:0;
transition:opacity 0.5s;
color:white;
}
.toggleGraph:checked + table td span,
.graph tr:hover td span {
width:4em;
margin-left:-2em; /* 1/2 the declared width */
opacity:1;
}
} /* min-width:32em */
} /* grid only */
</style>
<title>Water Utilisation</title>
</head>
<body>
<br>
<br>
<br>
<table class="graph">
<caption>Water usage over the week<br><br><br><br></caption>
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Percent</th>
</tr>
</thead><tbody>
"""
# The HTML code for the end of the website
html_end = """ </tbody>
</table>
</body>
</html>"""