From 82744075fdd8be41033463d6ee7134b1f63fd7c9 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 20 Apr 2019 01:50:10 +0200 Subject: Building minimal JSON datafiles + rewrites from ranking page URLs --- Makefile | 1 + bin/datafiles-build.sh | 1 + bin/datafiles-htaccess.sh | 17 +++++++++++++++++ http/.htaccess | 3 +++ scripts/datafiles-generate-minimal.py | 15 +++++++++++++++ 5 files changed, 37 insertions(+) create mode 100755 bin/datafiles-htaccess.sh create mode 100644 http/.htaccess create mode 100644 scripts/datafiles-generate-minimal.py diff --git a/Makefile b/Makefile index a918d5c..bbae274 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ rankings: datafiles menus tables editions group-json datafiles: bin/datafiles-build.sh config/dates.json http/_data + bin/datafiles-htaccess.sh config/dates.json http/.htaccess menus: bin/menus-build.sh config/static.json http diff --git a/bin/datafiles-build.sh b/bin/datafiles-build.sh index 5c336ff..ed9d8f9 100755 --- a/bin/datafiles-build.sh +++ b/bin/datafiles-build.sh @@ -7,5 +7,6 @@ cat $CONFIG | while read DATE do python scripts/datafiles-generate.py $DATE $PREV_DATE > "$DIR/$DATE.json" + python scripts/datafiles-generate-minimal.py $DATE > "$DIR/$DATE.minimal.json" PREV_DATE=$DATE done diff --git a/bin/datafiles-htaccess.sh b/bin/datafiles-htaccess.sh new file mode 100755 index 0000000..ab04bb0 --- /dev/null +++ b/bin/datafiles-htaccess.sh @@ -0,0 +1,17 @@ +#!/bin/bash +CONFIG=$1 +HTACCESS_FILE=$2 +cat $HTACCESS_FILE | + sed -e '/^# auto-generated from this point below$/,$d' > $HTACCESS_FILE.tmp +echo '' >> $HTACCESS_FILE.tmp +echo '# auto-generated from this point below' >> $HTACCESS_FILE.tmp +cat $CONFIG | + jq -r '.[] | .date, .url' | xargs -n 2 | + while read DATE URL + do + PREFIX="${URL//.html/}" + echo "RewriteRule $PREFIX.json _data/$DATE.json [L]" >> $HTACCESS_FILE.tmp + echo "RewriteRule $PREFIX.minimal.json _data/$DATE.minimal.json [L]" >> $HTACCESS_FILE.tmp + echo "RewriteRule $PREFIX.csv https://raw.githubusercontent.com/emkael/pzbs-ranking/master/data/rankings/$DATE.csv [R,L]" >> $HTACCESS_FILE.tmp + done +mv $HTACCESS_FILE.tmp $HTACCESS_FILE diff --git a/http/.htaccess b/http/.htaccess new file mode 100644 index 0000000..e12c5d6 --- /dev/null +++ b/http/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On + +# auto-generated from this point below diff --git a/scripts/datafiles-generate-minimal.py b/scripts/datafiles-generate-minimal.py new file mode 100644 index 0000000..896a1ec --- /dev/null +++ b/scripts/datafiles-generate-minimal.py @@ -0,0 +1,15 @@ +import json, sys + +from pyranking.fetch import fetch_ranking + +ranking_date = sys.argv[1] +ranking = fetch_ranking(ranking_date) + +output = {} +for row in ranking: + output[row['pid']] = { + 'p': row['place'], + 'r': float(row['score']) + } + +print json.dumps(output) -- cgit v1.2.3