Load and cache runs from GDQ site
This caches to the local filesystem because by default, Lambda calls (where this is targeted to run) share a filesystem as long as the lambda container is initializedmain
parent
625e7b1a6f
commit
767f211e8f
|
@ -2,4 +2,40 @@
|
|||
|
||||
.site-content {
|
||||
padding-top: 75px;
|
||||
}
|
||||
}
|
||||
|
||||
.the_table {
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #dfdfdf;
|
||||
}
|
||||
|
||||
.the_table th:nth-child(1) {
|
||||
width: 15%;
|
||||
}
|
||||
|
||||
.the_table th:nth-child(2) {
|
||||
width: 55%;
|
||||
}
|
||||
|
||||
.the_table th:nth-child(3) {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.the_table tr:nth-child(even) {
|
||||
background-color: #efefef;
|
||||
}
|
||||
|
||||
.the_table td,th {
|
||||
padding: 0.5em 2px;
|
||||
}
|
||||
|
||||
.the_table td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.de-emphasis {
|
||||
font-style: italic;
|
||||
color: #888888;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,24 @@
|
|||
{% block content %}
|
||||
|
||||
<div class="body-content">
|
||||
<div class="row">
|
||||
<h1>Welcome!</h1>
|
||||
</div>
|
||||
<div class="row">
|
||||
<h1>Summer Games Done Quick Schedulizer</h1>
|
||||
|
||||
<table class="the_table">
|
||||
<tr>
|
||||
<th scope="col">Time & Estimate</th>
|
||||
<th scope="col">Run</th>
|
||||
<th scope="col">Runners</th>
|
||||
</tr>
|
||||
{% for run in runs %}
|
||||
<tr class="{{run["class"]}}">
|
||||
<td>{{run["time"]}} → {{run["estimate"]}}</td>
|
||||
<td>{{run["name"]}} <span class="de-emphasis">{{run["category"]}}</span></td>
|
||||
<td>{{run["runners"]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -23,8 +23,11 @@ main_blueprint = Blueprint('main', __name__,)
|
|||
|
||||
@main_blueprint.route('/')
|
||||
def home():
|
||||
unpacked_set = set()
|
||||
return render_template('main/home.html')
|
||||
all_runs = fetch_or_cache_runs()
|
||||
return render_template(
|
||||
'main/home.html',
|
||||
runs=all_runs
|
||||
)
|
||||
|
||||
|
||||
@main_blueprint.route("/about/")
|
||||
|
@ -34,4 +37,9 @@ def about():
|
|||
@main_blueprint.route("/<preferences>")
|
||||
def returning_user(preferences):
|
||||
unpacked_set = unpack_ints(preferences)
|
||||
return render_template("main/home.html")
|
||||
all_runs = fetch_or_cache_runs()
|
||||
runs = inject_run_class(all_runs, unpacked_set)
|
||||
return render_template(
|
||||
"main/home.html",
|
||||
runs=runs
|
||||
)
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
# kappa123/server/runs.py
|
||||
|
||||
import os
|
||||
import requests
|
||||
import simplejson as json
|
||||
import arrow
|
||||
|
||||
CACHE_LOCATION='/tmp/runs.json'
|
||||
|
||||
def inject_run_class(runs, selected_runs):
|
||||
output = list()
|
||||
for run in raw_data:
|
||||
run = run['fields']
|
||||
d = {
|
||||
'time': arrow.get(run['starttime']).format('HH:mm:ss'),
|
||||
'estimate': run['run_time'],
|
||||
'name': run['name'],
|
||||
'category': run['category'],
|
||||
'runners': run['deprecated_runners'] #lol
|
||||
}
|
||||
output.append(d)
|
||||
return output
|
||||
|
||||
|
||||
def fetch_or_cache_runs():
|
||||
if os.path.isfile(CACHE_LOCATION):
|
||||
with open(CACHE_LOCATION, 'r') as f:
|
||||
string = f.read()
|
||||
return transform_runs(json.loads(string))
|
||||
else:
|
||||
r = requests.get('https://gamesdonequick.com/tracker/search/?type=run&event=20')
|
||||
if r.status_code != 200:
|
||||
raise Exception("GDQ not returning 200")
|
||||
output = r.json()
|
||||
with open(CACHE_LOCATION, 'w') as f:
|
||||
f.write(r.text)
|
||||
return transformed_runs(output)
|
||||
|
||||
|
||||
def transform_runs(raw_data):
|
||||
"""Transform a JSON list of GDQ runs from their site in to simplified dict for rendering here."""
|
||||
output = list()
|
||||
for run in raw_data:
|
||||
run = run['fields']
|
||||
d = {
|
||||
'time': arrow.get(run['starttime']).format('HH:mm:ss'),
|
||||
'estimate': run['run_time'],
|
||||
'name': run['name'],
|
||||
'category': run['category'],
|
||||
'runners': run['deprecated_runners'] #lol
|
||||
}
|
||||
output.append(d)
|
||||
return output
|
|
@ -1,11 +1,7 @@
|
|||
coverage==4.3.4
|
||||
Flask==0.12
|
||||
Flask-Bcrypt==0.7.1
|
||||
Flask-Bootstrap==3.3.7.1
|
||||
Flask-DebugToolbar==0.10.0
|
||||
Flask-Login==0.4.0
|
||||
Flask-Migrate==2.0.3
|
||||
Flask-Script==2.0.5
|
||||
Flask-SQLAlchemy==2.1
|
||||
Flask-Testing==0.6.1
|
||||
Flask-WTF==0.14.2
|
||||
|
||||
simplejson
|
||||
requests
|
||||
arrow
|
||||
|
|
Loading…
Reference in New Issue