summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-09-07 14:25:44 +0200
committeremkael <emkael@tlen.pl>2017-09-07 14:25:44 +0200
commit9653e31ca7ef40a408d176d338cd93a8076b3318 (patch)
tree8cc650557703294e187a6ce8eb8aea231430e62b
parent91b4d644cf8064457d5365dc1642ad8ab5f87be3 (diff)
Pre-generating menu content for players pages
Fixes #11
-rwxr-xr-xbin/build-players.sh2
-rw-r--r--scripts/players.py10
2 files changed, 9 insertions, 3 deletions
diff --git a/bin/build-players.sh b/bin/build-players.sh
index 3f123bd..e1d099d 100755
--- a/bin/build-players.sh
+++ b/bin/build-players.sh
@@ -1,4 +1,4 @@
#!/bin/bash
DIR=$1
mkdir -p $DIR/players
-python scripts/players.py $DIR/players
+python scripts/players.py $DIR/players $DIR/players/.menu.html
diff --git a/scripts/players.py b/scripts/players.py
index 7799972..613c01f 100644
--- a/scripts/players.py
+++ b/scripts/players.py
@@ -6,6 +6,9 @@ from pyranking.fetch import fetch_ranking
output_directory = sys.argv[1]
pagesize = 100.0
+menu_file = sys.argv[2]
+menu_content = bs4(file(menu_file), 'html.parser')
+
dates = {}
for date_config in json.load(file('config/dates.json')):
dates[date_config['date']] = date_config['url']
@@ -28,7 +31,6 @@ for date in sorted(dates.keys()):
players[player]['rankings'][date][field + '-change-class'] = 'primary'
for pid, player in players.iteritems():
-
template = bs4(file('templates/player.html'), 'lxml')
template.select('h2.name')[0].insert(0, player['name'])
template.select('h3.club')[0].string = player['club']
@@ -89,4 +91,8 @@ for pid, player in players.iteritems():
change_label.string = ranking[field+'change']
change_label['class'] = change_label['class'] + ['label-'+ranking[field+'change-class']]
template.select('table.table tbody')[0].insert(0, row)
- file(os.path.join(output_directory, '%d.html' % pid), 'w').write(template.prettify().encode('utf-8'))
+
+ menu = template.select('div.static-menu')[0]
+ menu.append(copy.copy(menu_content))
+
+ file(os.path.join(output_directory, '%d.html' % pid), 'w').write(template.prettify().encode('utf-8'))