From c2893bea6f777fabff815a90c0b6cbe506770ce0 Mon Sep 17 00:00:00 2001 From: Anton Sarukhanov <code@ant.sr> Date: Sun, 25 Mar 2018 13:26:52 -0400 Subject: [PATCH] Make protocol prefix and trailing slash optional. Add refresh, extra Escrime URLs, optgroups. --- scrape.py | 14 ++++++++++---- templates/base.html | 3 ++- templates/index.html | 22 ++++++++++++++++++---- templates/live.html | 3 +++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/scrape.py b/scrape.py index c35f3fd..10c519d 100644 --- a/scrape.py +++ b/scrape.py @@ -6,7 +6,10 @@ from itertools import repeat def scrape(results_url): - results = requests.get(results_url) + try: + results = requests.get(results_url) + except requests.exceptions.MissingSchema: + results = requests.get("http://{}".format(results_url)) results_tree = html.fromstring(results.content) try: event_urls = results_tree.xpath( @@ -20,13 +23,16 @@ def scrape(results_url): events = [] for event_url in event_urls: if not urlparse(event_url).netloc: - event_url = urljoin(results_url, event_url) + event_url = urljoin(results.url, event_url) event = requests.get(event_url) event_tree = html.fromstring(event.content) event_details = event_tree.xpath( '//span[@class="tournDetails"]/text()') - event_name = event_details[0] - event_time = event_details[1] + try: + event_name = event_details[0] + event_time = event_details[1] + except: + raise(Exception("Failed to interpret live results for event \"{}\".".format(event_url))) if event_tree.xpath('//a[text()="Final Results"]'): fencers = event_tree.xpath('//div[@id="finalResults"]/table/tr/td[2]/text()') fencers = dict(zip(fencers, repeat("Checked In"))) diff --git a/templates/base.html b/templates/base.html index ad0814a..6ed2e21 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <title>Armory Dashboard</title> - <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=0"> + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}?t=20180325"> <link rel="apple-touch-icon" sizes="180x180" href="{{ url_for('static', filename='images/icons/apple-touch-icon.png') }}?t=20180325"> <link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='images/icons/favicon-32x32.png') }}?t=20180325"> @@ -16,6 +16,7 @@ <meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-config" content="{{ url_for('static', filename='images/icons/browserconfig.xml') }}?t=20180325"> <meta name="theme-color" content="#ffffff"> + {% block extra_head %}{% endblock extra_head %} </head> <body class="page-{{ request.endpoint }}"> {% block content %}{% endblock content %} diff --git a/templates/index.html b/templates/index.html index d3df7ed..5e8386c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,9 +12,23 @@ <label>Live Results URL: <select name="results_url"> <option value="" selected disabled>-- Select One --</option> - <option value="http://escrimeresults.com/cobra/">Cobra</option> - <option value="http://escrimeresults.com/thrust/">Thrust</option> - <option value="http://njfencingresults.org/liveresults/">NJFencingResults.org</option> + <optgroup label="Escrime Management"> + <option value="http://escrimeresults.com/tournaments/NCAA.html">NCAA</option> + <option value="http://escrimeresults.com/tournaments/Atlantic-Coast-Conference.html">Atlantic Coast Conference</option> + <option value="http://escrimeresults.com/tournaments/Ivy-League.html">Ivy League</option> + <option value="http://escrimeresults.com/cobra/">Cobra</option> + <option value="http://escrimeresults.com/thrust/">Thrust</option> + <option value="http://escrimeresults.com/tournaments/NJSIAA.html">NJSIAA</option> + <option value="http://escrimeresults.com/Candlewood/">Candlewood</option> + <option value="http://escrimeresults.com/tournaments/U-Penn.html">U Penn</option> + <option value="http://escrimeresults.com/tournaments/Temple-University.html">Temple U</option> + <option value="http://escrimeresults.com/Big1/">Big1</option> + <option value="http://escrimeresults.com/tournaments/US-Collegiate-Squad-Championships.html">US Collegiate Squad</option> + <option value="http://escrimeresults.com/MKHS/">MKHS</option> + </optgroup> + <optgroup label="NJ Division"> + <option value="http://njfencingresults.org/liveresults/">NJFencingResults.org/liveresults</option> + </optgroup> </select> </label> <input type="submit" value="Go!"> @@ -23,7 +37,7 @@ <p> <form action="{{ url_for('live') }}" method="get"> <label>Other URL: - <input name="results_url" placeholder="http://example.com/liveresults"> + <input name="results_url" placeholder="example.com/liveresults"> </label> <input type="submit" value="Go!"> </form> diff --git a/templates/live.html b/templates/live.html index 9280dfe..f124ee6 100644 --- a/templates/live.html +++ b/templates/live.html @@ -1,4 +1,7 @@ {% extends "base.html" %} +{% block extra_head %} + <meta http-equiv="refresh" content="60; URL={{ url_for('live') }}"> +{% endblock extra_head %} {% block content %} <header> <span class="back-to-home"><a href="{{ url_for('index') }}">Back to Home</a></span> -- GitLab