diff --git a/scrape.py b/scrape.py index aee97749e246466109fe43f35c15bc19c3041a6f..bcad8d8cdd039d30cf0697d147de8a71909ac761 100644 --- a/scrape.py +++ b/scrape.py @@ -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) diff --git a/templates/index.html b/templates/index.html index e34ef7304ac0796b360db112f31c8a43629b8e5a..4a6c6be65bbb78b9e9c165f7d09c0c47ebb01246 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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>