diff --git a/kappa123/client/static/main.css b/kappa123/client/static/main.css index 3ec203c..3036622 100644 --- a/kappa123/client/static/main.css +++ b/kappa123/client/static/main.css @@ -2,4 +2,40 @@ .site-content { padding-top: 75px; -} \ No newline at end of file +} + +.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; +} diff --git a/kappa123/client/templates/main/home.html b/kappa123/client/templates/main/home.html index 2bd944a..ec47f58 100644 --- a/kappa123/client/templates/main/home.html +++ b/kappa123/client/templates/main/home.html @@ -3,9 +3,24 @@ {% block content %}
-
-

Welcome!

-
+
+

Summer Games Done Quick Schedulizer

+ + + + + + + + {% for run in runs %} + + + + + + {% endfor %} +
Time & EstimateRunRunners
{{run["time"]}} → {{run["estimate"]}}{{run["name"]}} {{run["category"]}}{{run["runners"]}}
+
{% endblock %} diff --git a/kappa123/server/main/views.py b/kappa123/server/main/views.py index fbbe47b..aa2a531 100644 --- a/kappa123/server/main/views.py +++ b/kappa123/server/main/views.py @@ -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("/") 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 + ) diff --git a/kappa123/server/runs.py b/kappa123/server/runs.py new file mode 100644 index 0000000..f7e9e7b --- /dev/null +++ b/kappa123/server/runs.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 689a300..271d7e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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