From da4e3a5b6670e5116c95d7c6db8d7155d66968e6 Mon Sep 17 00:00:00 2001 From: emkael Date: Fri, 14 Apr 2017 01:56:17 +0200 Subject: Dates config expanded, standard path included in uniform build scripts --- bin/build.sh | 20 ++++++++++++++++++++ bin/make-test.sh | 9 +-------- bin/make.sh | 4 +--- config/dates.json | 4 +--- config/prod-dates.json | 8 ++++++++ config/test-dates.json | 18 ++++++++++++++---- docs/building.md | 4 ++-- editions.py | 18 +++++++++++------- players.py | 5 +++-- 9 files changed, 61 insertions(+), 29 deletions(-) create mode 100755 bin/build.sh mode change 100644 => 120000 config/dates.json create mode 100644 config/prod-dates.json diff --git a/bin/build.sh b/bin/build.sh new file mode 100755 index 0000000..4cd0f90 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +CONFIG=$1 +DIR=$2 +rm config/dates.json +ln -s $CONFIG config/dates.json +PREV_DATE="" +cat config/dates.json | + jq '.[] | .date, .url, .index, .name' | + xargs -n4 | + while read DATE URL INDEX NAME + do + python ranking.py $DATE $PREV_DATE > $DIR/$URL + PREV_DATE=$DATE + done +find $DIR -maxdepth 1 -type f -name \*.html | + while read FILE + do + python editions.py $FILE + done +python players.py $DIR/players diff --git a/bin/make-test.sh b/bin/make-test.sh index e93634f..49961ec 100755 --- a/bin/make-test.sh +++ b/bin/make-test.sh @@ -1,9 +1,2 @@ #!/bin/bash -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 +bin/build.sh test-dates.json http/test diff --git a/bin/make.sh b/bin/make.sh index ed8ff4a..55f5e77 100755 --- a/bin/make.sh +++ b/bin/make.sh @@ -1,4 +1,2 @@ #!/bin/bash -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 +bin/build.sh prod-dates.json http diff --git a/config/dates.json b/config/dates.json deleted file mode 100644 index 7dfdd66..0000000 --- a/config/dates.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "2016-12-31": "." -} diff --git a/config/dates.json b/config/dates.json new file mode 120000 index 0000000..f302866 --- /dev/null +++ b/config/dates.json @@ -0,0 +1 @@ +prod-dates.json \ No newline at end of file diff --git a/config/prod-dates.json b/config/prod-dates.json new file mode 100644 index 0000000..d086a9d --- /dev/null +++ b/config/prod-dates.json @@ -0,0 +1,8 @@ +[ + { + "date": "2016-12-31", + "url": "index.html", + "name": "I 2017", + "index": "1" + } +] diff --git a/config/test-dates.json b/config/test-dates.json index f417da7..d7ac8f8 100644 --- a/config/test-dates.json +++ b/config/test-dates.json @@ -1,4 +1,14 @@ -{ - "2016-12-31": "2017-01.html", - "2017-04-30": "." -} +[ + { + "date": "2016-12-31", + "url": "2017-01.html", + "name": "I 2017", + "index": "1" + }, + { + "date": "2017-04-30", + "url": "index.html", + "name": "II 2017", + "index": "2" + } +] diff --git a/docs/building.md b/docs/building.md index 1d12302..272a7fd 100644 --- a/docs/building.md +++ b/docs/building.md @@ -13,12 +13,12 @@ python ranking.py DATE PREVIOUS_DATE > http/FILENAME.html To compile edition list header into ranking: ``` -python editions.py DATE_CONFIG http/FILENAME.html +python editions.py http/FILENAME.html ``` To build players' pages: ``` -python players.py http/players/ [DATES_CONFIG] +python players.py http/players/ ``` Name, surname and club are always used from the current `players` table. Regions, genders and age categories are read per-ranking. diff --git a/editions.py b/editions.py index 3db438a..42d036f 100644 --- a/editions.py +++ b/editions.py @@ -2,15 +2,19 @@ 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') +dates_config = json.load(file('config/dates.json')) +output_file = bs4(file(sys.argv[1]), 'lxml') editions = {} -for date, link in dates_config.iteritems(): - year = date.split('-')[0] +for date_config in dates_config: + year = date_config['name'].split(' ')[1] if year not in editions: editions[year] = [] - editions[year].append(('.'.join(date.split('-')[::-1][0:2]), link, date)) + editions[year].append(( + '%s (%s)' % (date_config['name'].split(' ')[0], date_config['index']), + date_config['url'], + date_config['date'] + )) template = bs4(file('templates/ranking.html'), 'lxml') @@ -20,7 +24,7 @@ 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: + for date in dates[::-1]: link = copy.copy(ranking_link) link.string = date[0] link['href'] = date[1] @@ -29,4 +33,4 @@ for year, dates in editions.iteritems(): 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')) +file(sys.argv[1], 'w').write(output_file.prettify().encode('utf-8')) diff --git a/players.py b/players.py index a9ff20a..bceeb15 100644 --- a/players.py +++ b/players.py @@ -3,9 +3,10 @@ from bs4 import BeautifulSoup as bs4 from pyranking.fetch import fetch_ranking output_directory = sys.argv[1] -config_file = sys.argv[2] if len(sys.argv) > 2 else 'dates.json' -dates = json.load(file(config_file)) +dates = {} +for date_config in json.load(file('config/dates.json')): + dates[date_config['date']] = date_config['url'] players = {} -- cgit v1.2.3