From e76bf109dae2ecd41c4fcd96a54d0089a52480b4 Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Sun, 27 Nov 2016 13:02:44 -0500
Subject: [PATCH] Fix checked-in detection; clean up words.

---
 scrape.py            | 10 ++++------
 templates/index.html | 21 +++++++++++----------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/scrape.py b/scrape.py
index bcad8d8..66a6528 100644
--- a/scrape.py
+++ b/scrape.py
@@ -31,15 +31,14 @@ def scrape():
         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))
+            event_status = "Event has closed.".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))
+            event_status = "Event is ongoing.".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()')
+            event_status = "Check-in is open."
+            fencers_checked_in = [True if len(list(f)) else False for f in event_tree.xpath('//div[@id="checkIn"]/table/tr/td[1]')]
             fencers = event_tree.xpath('//div[@id="checkIn"]/table/tr/td[2]/text()')
             fencers = dict(zip(fencers, fencers_checked_in))
         try:
@@ -57,7 +56,6 @@ def scrape():
             'previous_total': 0
         }
         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:
diff --git a/templates/index.html b/templates/index.html
index 4a6c6be..fa719c7 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -34,26 +34,27 @@
     </style>
 </head>
 <body>
-    <h1>{{tournament_name}}</h1>
-    <h2>{{tournament_details}}</h2>
-    <h2>{{events|length}} Events</h2>
+    <h1>{{ tournament_name }}</h1>
+    <h2>{{ tournament_details }}</h2>
+    <h2>{{ events|length }} Events</h2>
     <hr>
     {% for e in events %}
     <section>
-    <a name="{{e['name']}}">
-    <h3><a href="#{{e['name']}}">{{e['name']}}</a></h3>
-    <h4>{{e['time']}}</h4>
-    <p>{{e['status']}}</p>
+    <a name="{{ e['name'] }}">
+    <h3><a href="#{{ e['name'] }}">{{ e['name'] }}</a></h3>
+    <h4>{{ e['time'] }}</h4>
+    <p>{{ e['status'] }}</p>
+    <p><strong>{{ e['fencers_checked_in']|length }}</strong> of <strong>{{ e['fencers']|len }}</strong> fencers have checked in.</p>
     {% if e['previously_fenced'] %}
-    <p>{{e['previous_total']}} fencers have participated in prior events:</p>
+    <p><strong>{{ e['previous_total'] }}</strong> fencers have participated in prior events:</p>
     <ul>
     {% for pe in e['previously_fenced'] %}
-        <li>{{pe}} - {{e['previously_fenced'][pe]}} fencers</li>
+        <li><strong>{{ pe }}</strong> - {{ e['previously_fenced'][pe] }} fencers</li>
     {% 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>
+    <p class="hl">{{ e['new_fencers_not_checked_in']|length }} new fencers not yet checked in</p>
     {% endif %}
     </section>
     {% endfor %}
-- 
GitLab