From 70d338228266fa4741c61387acc2bb38d731031f Mon Sep 17 00:00:00 2001 From: Urban Guacamole Date: Fri, 22 Feb 2019 15:21:13 +0100 Subject: [PATCH] Further automate index updates --- index-generator/fix-metajson.py | 25 +++++++++++++++++++++++++ update-index.sh | 10 ++++------ website/bundle.js | 1 + website/index.html | 1 + website/view.js | 2 +- 5 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 index-generator/fix-metajson.py diff --git a/index-generator/fix-metajson.py b/index-generator/fix-metajson.py new file mode 100644 index 0000000..f17d1f4 --- /dev/null +++ b/index-generator/fix-metajson.py @@ -0,0 +1,25 @@ +# Helper script to fix meta.json; add resultPage and count. +# First cmd param: what was passed to index-generator as inxpath. ex.: ../website/generated/inx + +import os +import sys +import io +import json + +def count_torrents_in_index(inxpath, blocksize): + files = os.listdir(os.path.dirname(inxpath)) + + def filterfiles(item): + return "inx" in item + + inxfiles = filter(filterfiles,files) + return sum(1 for _ in inxfiles)*blocksize + + +meta = json.load(io.open(sys.argv[1]+".meta.json","r")) +meta["resultPage"] = "resultpage" +meta["entries"] = count_torrents_in_index(sys.argv[1],1000) +meta["inxUrlBase"] = "website/generated/inx" +meta["invUrlBase"] = "website/generated/inv" + +json.dump(meta,io.open(sys.argv[1]+".meta.json", "w")) diff --git a/update-index.sh b/update-index.sh index 530079b..bc51bf2 100755 --- a/update-index.sh +++ b/update-index.sh @@ -14,17 +14,15 @@ echo "Preparing sqlite DB" sqlite3 index-generator/db.sqlite3 "CREATE TABLE peercount ( infohash char(40), tracker varchar, seeders int, leechers int, completed int, scraped timestamp, ws boolean);" sqlite3 index-generator/db.sqlite3 "CREATE TABLE torrent( infohash char(40), name varchar, length bigint, added timestamp);" echo """Do the following: -$ sqlite3 index-generator/db.sqlite3 sqlite> BEGIN; sqlite> .read index-generator/dump.sql sqlite> END;""" -bash +sqlite3 index-generator/db.sqlite3 echo "Generating index now..." (cd index-generator; node --max-old-space-size=10000 main.js) -echo "Check meta.json, add resultPage:'resultpage', fix invURLBase, inxURLBase" -nano website/generated/inx.meta.json +python3 index-generator/fix-metajson.py website/generated/inx + echo "Uploading website" cd website -scp -r . user@server:/www/torrent-paradise.ml -echo "Finished uploading website to server." \ No newline at end of file +scp -r . root@server:/www/torrent-paradise.ml #todo use rsync https://superuser.com/a/1405020/373473 diff --git a/website/bundle.js b/website/bundle.js index 2138ef9..d777da6 100644 --- a/website/bundle.js +++ b/website/bundle.js @@ -142,6 +142,7 @@ async function loadMeta(metaURL) { app.showsearchbox = true; app.indexAuthor = meta.author; app.indexName = meta.name; + app.entries = meta.entries; let ts = new Date(meta.created); app.indexTimestamp = ts.getDate().toString() + "/" + (ts.getMonth()+1).toString() + "/" + ts.getFullYear().toString(); if (meta.resultPage == undefined) { diff --git a/website/index.html b/website/index.html index 7c17c6a..8a7708b 100644 --- a/website/index.html +++ b/website/index.html @@ -41,6 +41,7 @@

Last index update: {{indexTimestamp}}

+

Torrents in index: {{entries}}

\ No newline at end of file diff --git a/website/view.js b/website/view.js index 1712db8..ac4754a 100644 --- a/website/view.js +++ b/website/view.js @@ -1,6 +1,6 @@ app = new Vue({ el: '#app', - data: {showsearchbox: false, error: "", resultPage: "", resultPageHeight: 1} + data: {showsearchbox: false, error: "", resultPage: "", resultPageHeight: 1, entries: -1} }) window.addEventListener("message", receiveMessage, false);