summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-04-20 01:50:10 +0200
committeremkael <emkael@tlen.pl>2019-04-20 01:50:10 +0200
commit82744075fdd8be41033463d6ee7134b1f63fd7c9 (patch)
treed2197205ba235a5e4d5e8dca0383d4eb2ad11e71
parent80292c05a38bbce6a3472ce2c8c86bd3f43e7512 (diff)
Building minimal JSON datafiles + rewrites from ranking page URLs
-rw-r--r--Makefile1
-rwxr-xr-xbin/datafiles-build.sh1
-rwxr-xr-xbin/datafiles-htaccess.sh17
-rw-r--r--http/.htaccess3
-rw-r--r--scripts/datafiles-generate-minimal.py15
5 files changed, 37 insertions, 0 deletions
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)