From 361c75c6f7e890626486488359f9b5ce368f884b Mon Sep 17 00:00:00 2001 From: randogoth Date: Mon, 22 May 2023 11:25:46 +0300 Subject: [PATCH] progress count --- userdb/db.py | 7 +++++-- web/nfc-theme/static/user.js | 11 ++++++++++- web/nfc-theme/templates/article.html | 23 +++++++++++++++-------- web/nfc-theme/templates/base.html | 28 ++++++++++++++-------------- web/pelicanconf.py | 8 ++++---- web/plugins/geodata/geodata.py | 7 +++++-- 6 files changed, 53 insertions(+), 31 deletions(-) diff --git a/userdb/db.py b/userdb/db.py index 2c3504b..413e159 100644 --- a/userdb/db.py +++ b/userdb/db.py @@ -18,9 +18,12 @@ app = Flask(__name__) @app.route("/track", methods = ['GET']) def track(): if request.method == 'GET' and request.args.get('hash'): + hash = str(request.args.get('hash')) + cat = str(request.args.get('cat')) ua = str(request.args.get('ua')) url = str(request.values.get("url") or request.headers.get("Referer")) + if os.path.exists('db.json'): with open('db.json', 'r') as db: db = json.loads(db.read()) @@ -35,7 +38,7 @@ def track(): visits = list(set(visits)) db.update({ hash : { - 'visits' : visits, + cat : visits, 'agent' : ua } }) @@ -45,7 +48,7 @@ def track(): with open('db.json', 'w+') as dbw: dbw.write(json.dumps(db, indent=4)) - return str(len(db[hash])) + return str(len(db[hash][cat])) else: return 'hash missing' diff --git a/web/nfc-theme/static/user.js b/web/nfc-theme/static/user.js index 296ed76..bed26af 100644 --- a/web/nfc-theme/static/user.js +++ b/web/nfc-theme/static/user.js @@ -22,7 +22,16 @@ if ( !Cookies.get('nfcexplorer') ) { Cookies.set('nfcexplorer', generateUUID()) } +cat = document.querySelector('meta[data-category]').content + fetch('https://nmns.place/track?' + new URLSearchParams({ hash: Cookies.get('nfcexplorer'), ua: ua, -})); \ No newline at end of file + cat: cat +})).then(response => { + progress = document.querySelector('span#progress').content + document.querySelector('span#progress').content = response +}) +.catch(error => { + // handle the error +}); \ No newline at end of file diff --git a/web/nfc-theme/templates/article.html b/web/nfc-theme/templates/article.html index 8f8e317..424e7e7 100644 --- a/web/nfc-theme/templates/article.html +++ b/web/nfc-theme/templates/article.html @@ -1,13 +1,20 @@ {% extends "base.html" %} +{% block head %} + + + + +{% endblock head %} {% block content %} -
-
- {{ article.content }} - {% if article.metadata.geohash %} - Map - {% endif %} -
-
+
+
+ {{ article.content }} + {% if article.metadata.geohash %} + Map + {% for cat, art in categories %}{% if cat.slug == category.slug %}{{ art|count }}{% endif %}{% endfor %} + {% endif %} +
+
{% endblock %} {% block scripts %} diff --git a/web/nfc-theme/templates/base.html b/web/nfc-theme/templates/base.html index d25a5ee..8554980 100644 --- a/web/nfc-theme/templates/base.html +++ b/web/nfc-theme/templates/base.html @@ -1,25 +1,25 @@ - {% block title %}{{ SITENAME }}{% endblock title %} - {% block head %} - - - - {% endblock head %} + {% block title %}{{ SITENAME }}{% endblock title %} + {% block head %} + + + + {% endblock head %} - {% block content %} - {% endblock %} + {% block content %} + {% endblock %} - {% if DESCRIPTION %} - - {% endif %} + {% if DESCRIPTION %} + + {% endif %} {% block scripts %} diff --git a/web/pelicanconf.py b/web/pelicanconf.py index 2e57ecc..6ffd869 100644 --- a/web/pelicanconf.py +++ b/web/pelicanconf.py @@ -52,10 +52,10 @@ PAGE_PATHS = ['pages',] SUMMARY_MAX_LENGTH = 0 DEFAULT_DATE_FORMAT = '%Y-%m-%d' -DEFAULT_CATEGORY = 'tag' -CATEGORIES_SAVE_AS = 'projects/index.html' -CATEGORY_URL = 'projects/{slug}' -CATEGORY_SAVE_AS = 'projects/{slug}/index.html' +DEFAULT_CATEGORY = 'ad-hoc' +CATEGORIES_SAVE_AS = 'zones/index.html' +CATEGORY_URL = 'zone/{slug}' +CATEGORY_SAVE_AS = 'zone/{slug}/index.html' DELETE_OUTPUT_DIRECTORY = True diff --git a/web/plugins/geodata/geodata.py b/web/plugins/geodata/geodata.py index 9996c3d..faf7197 100644 --- a/web/plugins/geodata/geodata.py +++ b/web/plugins/geodata/geodata.py @@ -33,7 +33,7 @@ def makeKML(): point.appendChild( coordinates ) placemark.appendChild( point ) root.childNodes[0].childNodes[0].childNodes[0].appendChild( placemark ) - with open('output/projects/' + category + '.kml', 'w') as xml_file: + with open(collection[category]["path"] + '.kml', 'w') as xml_file: root.writexml(xml_file, indent="", addindent=" ", newl='\n') def makeGPX(): @@ -50,10 +50,12 @@ def makeGPX(): name.appendChild( title ) wpt.appendChild( name ) root.childNodes[0].appendChild( wpt ) - with open('output/projects/' + category + '.gpx', 'w') as xml_file: + with open( collection[category]["path"] + '.gpx', 'w') as xml_file: root.writexml(xml_file, indent="", addindent=" ", newl='\n') def geodata(generator): + output = generator.settings.get('OUTPUT_PATH') + filepath = generator.settings.get('CATEGORY_URL') for category, articles in generator.categories: locations = [] for article in articles: @@ -65,6 +67,7 @@ def geodata(generator): collection.update({ category.slug : { "name" : category.name, + "path" : output + '/' + filepath.replace('{slug}', category.slug), "points" : locations }})