diff options
-rwxr-xr-x | bin/make-test.sh | 9 | ||||
-rwxr-xr-x | bin/make.sh | 3 | ||||
-rw-r--r-- | editions.py | 32 | ||||
-rw-r--r-- | ranking.py | 28 |
4 files changed, 44 insertions, 28 deletions
diff --git a/bin/make-test.sh b/bin/make-test.sh index f4c14d5..e93634f 100755 --- a/bin/make-test.sh +++ b/bin/make-test.sh @@ -1,4 +1,9 @@ #!/bin/bash -python ranking.py config/test-dates.json 2016-12-31 > http/test/2017-01.html -python ranking.py config/test-dates.json 2017-04-30 2016-12-31 > http/test/index.html +python ranking.py 2016-12-31 > http/test/2017-01.html +python ranking.py 2017-04-30 2016-12-31 > http/test/index.html +find http/test -maxdepth 1 -type f -name \*.html | + while read FILE + do + python editions.py config/test-dates.json $FILE + done python players.py http/test/players config/test-dates.json diff --git a/bin/make.sh b/bin/make.sh index efee4f4..ed8ff4a 100755 --- a/bin/make.sh +++ b/bin/make.sh @@ -1,3 +1,4 @@ #!/bin/bash -python ranking.py config/dates.json 2016-12-31 > http/index.html +python ranking.py 2016-12-31 > http/index.html +python editions.py config/dates.json http/index.html python players.py http/players config/dates.json diff --git a/editions.py b/editions.py new file mode 100644 index 0000000..3db438a --- /dev/null +++ b/editions.py @@ -0,0 +1,32 @@ +import copy, json, sys + +from bs4 import BeautifulSoup as bs4 + +dates_config = json.load(file(sys.argv[1])) +output_file = bs4(file(sys.argv[2]), 'lxml') + +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)) + +template = bs4(file('templates/ranking.html'), 'lxml') + +date_group = template.select('#editions')[0].extract() +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) + +output_file.select('#editions')[0].replace_with(date_group) +file(sys.argv[2], 'w').write(output_file.prettify().encode('utf-8')) @@ -1,12 +1,11 @@ -import copy, json, sys +import copy, sys from bs4 import BeautifulSoup as bs4 from pyranking.fetch import fetch_ranking -dates_config = json.load(file(sys.argv[1])) -ranking_date = sys.argv[2] +ranking_date = sys.argv[1] ranking = fetch_ranking(ranking_date) -old_ranking = fetch_ranking(sys.argv[3], True) if len(sys.argv) > 3 else {} +old_ranking = fetch_ranking(sys.argv[2], True) if len(sys.argv) > 2 else {} for row in ranking: if row['pid'] in old_ranking: @@ -55,25 +54,4 @@ 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') |