From bb087f62e6434c032644d030446ab781837ae5dd Mon Sep 17 00:00:00 2001
From: emkael
Date: Tue, 11 Apr 2017 18:32:08 +0200
Subject: Previous editions in header panel
---
ranking.py | 31 +++++++++++--
templates/ranking.html | 121 +++++++++++++++++++++++++++----------------------
2 files changed, 94 insertions(+), 58 deletions(-)
diff --git a/ranking.py b/ranking.py
index 72ef794..6ee3e3b 100644
--- a/ranking.py
+++ b/ranking.py
@@ -1,10 +1,12 @@
-import copy, sys
+import copy, json, sys
from bs4 import BeautifulSoup as bs4
from pyranking.fetch import fetch_ranking
-ranking = fetch_ranking(sys.argv[1])
-old_ranking = fetch_ranking(sys.argv[2], True) if len(sys.argv) > 2 else {}
+dates_config = json.load(file(sys.argv[1]))
+ranking_date = sys.argv[2]
+ranking = fetch_ranking(ranking_date)
+old_ranking = fetch_ranking(sys.argv[3], True) if len(sys.argv) > 3 else {}
for row in ranking:
if row['pid'] in old_ranking:
@@ -28,7 +30,7 @@ table_body = table.select('tbody')[0]
table_row = table_body.select('tr')[0].extract()
table.select('.page-header h1 small')[0].string = 'stan na %s' % (
- '.'.join(sys.argv[1].split('-')[::-1])
+ '.'.join(ranking_date.split('-')[::-1])
)
for row in ranking:
@@ -53,4 +55,25 @@ for row in ranking:
new_row['class'] = new_row.get('class', []) + ['info']
table_body.append(new_row)
+editions = {}
+for date, link in dates_config.iteritems():
+ year = date.split('-')[0]
+ if year not in editions:
+ editions[year] = []
+ editions[year].append(('.'.join(date.split('-')[::-1][0:2]), link, date))
+
+date_group = table.select('#editions')[0]
+year_group = date_group.select('div[role="group"]')[0].extract()
+ranking_link = year_group.select('.btn-default')[0].extract()
+for year, dates in editions.iteritems():
+ group = copy.copy(year_group)
+ group.select('.year')[0].string = str(year)
+ for date in dates:
+ link = copy.copy(ranking_link)
+ link.string = date[0]
+ link['href'] = date[1]
+ link['datetime'] = date[2]
+ group.append(link)
+ date_group.append(group)
+
print table.prettify().encode('utf-8')
diff --git a/templates/ranking.html b/templates/ranking.html
index 72d3750..797cdef 100644
--- a/templates/ranking.html
+++ b/templates/ranking.html
@@ -59,60 +59,73 @@
-
-
-
- Miejsce |
- PID |
- Zawodnik |
- Klub |
- Okręg |
- Płeć |
- Kat. wiekowa |
- Wynik |
-
-
-
-
-
-
- |
-
-
- |
- |
-
-
-
-
- |
- |
- |
- |
-
-
- |
-
-
- |
- |
-
-
- |
-
-
- |
- |
-
-
- |
-
-
- |
- |
-
-
-
+
+
+ Wszystkie notowania rankingu
+
+
+
+
+
+
+
+ Miejsce |
+ PID |
+ Zawodnik |
+ Klub |
+ Okręg |
+ Płeć |
+ Kat. wiekowa |
+ Wynik |
+
+
+
+
+
+
+ |
+
+
+ |
+ |
+
+
+
+
+ |
+ |
+ |
+ |
+
+
+ |
+
+
+ |
+ |
+
+
+ |
+
+
+ |
+ |
+
+
+ |
+
+
+ |
+ |
+
+
+
+
--
cgit v1.2.3