diff options
-rw-r--r-- | ranking.py | 31 | ||||
-rw-r--r-- | templates/ranking.html | 121 |
2 files changed, 94 insertions, 58 deletions
@@ -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 @@ </p> </div> </div> - <table class="table table-striped table-hover table-condensed"> - <thead> - <tr class="text-center"> - <th colspan="2">Miejsce</th> - <th class="pid" colspan="2">PID</th> - <th>Zawodnik</th> - <th class="club">Klub</th> - <th class="region" colspan="3">Okręg</th> - <th class="gender" colspan="3">Płeć</th> - <th class="age" colspan="3">Kat. wiekowa</th> - <th class="ranking">Wynik</th> - </tr> - </thead> - <tbody> - <tr> - <td class="place text-right"> - <span class="rank"></span> - </td> - <td class="place"> - <span class="change label"></span> - </td> - <td class="pid text-right"></td> - <td class="pidlink"> - <a href="" target="_blank"> - <span class="glyphicon glyphicon-new-window"></span> - </a> - </td> - <td class="name"></td> - <td class="club"></td> - <td class="region text-center"></td> - <td class="region-place text-right"> - <span class="rank"></span> - </td> - <td class="region-place"> - <span class="change label"></span> - </td> - <td class="gender text-center"></td> - <td class="gender-place text-right"> - <span class="rank"></span> - </td> - <td class="gender-place"> - <span class="change label"></span> - </td> - <td class="age text-center"></td> - <td class="age-place text-right"> - <span class="rank"></span> - </td> - <td class="age-place"> - <span class="change label"></span> - </td> - <td class="ranking text-right"></td> - </tr> - </tbody> - </table> + <div class="panel panel-default"> + <div class="panel-heading" role="button" data-toggle="collapse" data-target="#editions" aria-expanded="false" aria-controls="editions"> + Wszystkie notowania rankingu + </div> + <div class="collapse panel-body" id="editions"> + <div class="btn-group" role="group"> + <button type="button" class="btn btn-disabled year" /> + <a href="" class="btn btn-default" datetime=""></a> + </div> + </div> + </div> + <div class="table-responsive"> + <table class="table table-striped table-hover table-condened"> + <thead> + <tr class="text-center"> + <th colspan="2">Miejsce</th> + <th class="pid" colspan="2">PID</th> + <th>Zawodnik</th> + <th class="club">Klub</th> + <th class="region" colspan="3">Okręg</th> + <th class="gender" colspan="3">Płeć</th> + <th class="age" colspan="3">Kat. wiekowa</th> + <th class="ranking">Wynik</th> + </tr> + </thead> + <tbody> + <tr> + <td class="place text-right"> + <span class="rank"></span> + </td> + <td class="place"> + <span class="change label"></span> + </td> + <td class="pid text-right"></td> + <td class="pidlink"> + <a href="" target="_blank"> + <span class="glyphicon glyphicon-new-window"></span> + </a> + </td> + <td class="name"></td> + <td class="club"></td> + <td class="region text-center"></td> + <td class="region-place text-right"> + <span class="rank"></span> + </td> + <td class="region-place"> + <span class="change label"></span> + </td> + <td class="gender text-center"></td> + <td class="gender-place text-right"> + <span class="rank"></span> + </td> + <td class="gender-place"> + <span class="change label"></span> + </td> + <td class="age text-center"></td> + <td class="age-place text-right"> + <span class="rank"></span> + </td> + <td class="age-place"> + <span class="change label"></span> + </td> + <td class="ranking text-right"></td> + </tr> + </tbody> + </table> + </div> <div class="well well-sm"> © 2017 - dla <a href="http://pzbs.pl">PZBS</a> zrobił <a href="https://emkael.info">mkl.</a> Też sobie <a href="https://github.com/emkael/pzbs-ranking">zrób.</a> </div> |