Skip to content
Snippets Groups Projects
Commit d3da3019 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

Count checked-in fencers

parent 65aabd8d
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ from lxml import html
import requests
import re
from urllib.parse import urlparse, urljoin
from itertools import repeat
def scrape():
......@@ -29,38 +30,53 @@ def scrape():
event_time = event_details[1]
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")))
event_status = "Event Closed ({0} fencers)".format(len(fencers))
elif event_tree.xpath('//a[text()="Seeding"]'):
fencers = event_tree.xpath('//div[@id="Round1Seeding"]/table/tr/td[2]/text()')
fencers = dict(zip(fencers, repeat("Checked In")))
event_status = "Event is Ongoing ({0} fencers)".format(len(fencers))
elif event_tree.xpath('//a[text()="Check-In Status"]'):
event_status = event_tree.xpath(
'normalize-space(//div[@class="checkInSummary"]/text())')
fencers_checked_in = event_tree.xpath('//div[@id="checkIn"]/table/tr/td[1]/text()')
fencers = event_tree.xpath('//div[@id="checkIn"]/table/tr/td[2]/text()')
fencers = dict(zip(fencers, fencers_checked_in))
try:
del this_event
except:
pass
pass # not yet set, oh well
this_event = {
'name': event_name,
'time': event_time,
'status': event_status,
'fencers': [],
'fencers_checked_in': [],
'new_fencers_not_checked_in': [],
'previously_fenced': {},
'previous_total': 0
}
for fencer in fencers:
this_event['fencers'].append(fencer.strip())
for fencer, is_checked_in in fencers.items():
is_checked_in = bool(is_checked_in.strip())
fencer = fencer.strip()
this_event['fencers'].append(fencer)
if is_checked_in:
this_event['fencers_checked_in'].append(fencer)
else:
this_event['new_fencers_not_checked_in'].append(fencer)
for e in events:
if e['name'] == event_details:
continue
if fencer.strip() in e['fencers']:
if fencer in e['fencers']:
if e['name'] in this_event['previously_fenced']:
this_event['previously_fenced'][e['name']] += 1
else:
this_event['previously_fenced'][e['name']] = 1
this_event['previous_total'] += 1
try:
this_event['new_fencers_not_checked_in'].remove(fencer)
except ValueError:
pass # already removed; ignore
break
events.append(this_event)
# TODO: Tally fencers who have checked in
return (tournament_name, tournament_details, events)
......@@ -6,10 +6,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font: 14px sans-serif;
font: 18px sans-serif;
}
section {
border-bottom: 1px dashed #aaa;
margin: 1em 0;
}
h1, h2, h3, h4, h5, h6 {
margin: .35em 0;
......@@ -27,6 +28,9 @@
text-decoration: underline;
color: #000;
}
.hl {
background-color: #ee8;
}
</style>
</head>
<body>
......@@ -48,6 +52,9 @@
{% endfor %}
</ul>
{% endif %}
{% if e['new_fencers_not_checked_in'] %}
<p class="hl">{{e['new_fencers_not_checked_in']|length}} new fencers not yet checked in</p>
{% endif %}
</section>
{% endfor %}
</body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment