summaryrefslogtreecommitdiff
path: root/scripts/rankings-editions.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-09-08 01:28:21 +0200
committeremkael <emkael@tlen.pl>2017-09-08 01:28:21 +0200
commit8f795b1d445441daab5ffb75060a6dbf8ed0934a (patch)
tree15e55a2a7e03867ac0cccfb8303674d478510503 /scripts/rankings-editions.py
parent655a9847513332e8e119f37f7ed95f4ab002b1a1 (diff)
Renaming scripts so that their names make sense
Diffstat (limited to 'scripts/rankings-editions.py')
-rw-r--r--scripts/rankings-editions.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/rankings-editions.py b/scripts/rankings-editions.py
new file mode 100644
index 0000000..42d036f
--- /dev/null
+++ b/scripts/rankings-editions.py
@@ -0,0 +1,36 @@
+import copy, json, sys
+
+from bs4 import BeautifulSoup as bs4
+
+dates_config = json.load(file('config/dates.json'))
+output_file = bs4(file(sys.argv[1]), 'lxml')
+
+editions = {}
+for date_config in dates_config:
+ year = date_config['name'].split(' ')[1]
+ if year not in editions:
+ editions[year] = []
+ 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')
+
+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[::-1]:
+ 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[1], 'w').write(output_file.prettify().encode('utf-8'))