progress count

This commit is contained in:
randogoth 2023-05-22 11:25:46 +03:00
parent 7f1a8e0a6c
commit 361c75c6f7
6 changed files with 53 additions and 31 deletions

View file

@ -18,9 +18,12 @@ app = Flask(__name__)
@app.route("/track", methods = ['GET']) @app.route("/track", methods = ['GET'])
def track(): def track():
if request.method == 'GET' and request.args.get('hash'): if request.method == 'GET' and request.args.get('hash'):
hash = str(request.args.get('hash')) hash = str(request.args.get('hash'))
cat = str(request.args.get('cat'))
ua = str(request.args.get('ua')) ua = str(request.args.get('ua'))
url = str(request.values.get("url") or request.headers.get("Referer")) url = str(request.values.get("url") or request.headers.get("Referer"))
if os.path.exists('db.json'): if os.path.exists('db.json'):
with open('db.json', 'r') as db: with open('db.json', 'r') as db:
db = json.loads(db.read()) db = json.loads(db.read())
@ -35,7 +38,7 @@ def track():
visits = list(set(visits)) visits = list(set(visits))
db.update({ db.update({
hash : { hash : {
'visits' : visits, cat : visits,
'agent' : ua 'agent' : ua
} }
}) })
@ -45,7 +48,7 @@ def track():
with open('db.json', 'w+') as dbw: with open('db.json', 'w+') as dbw:
dbw.write(json.dumps(db, indent=4)) dbw.write(json.dumps(db, indent=4))
return str(len(db[hash])) return str(len(db[hash][cat]))
else: else:
return 'hash missing' return 'hash missing'

View file

@ -22,7 +22,16 @@ if ( !Cookies.get('nfcexplorer') ) {
Cookies.set('nfcexplorer', generateUUID()) Cookies.set('nfcexplorer', generateUUID())
} }
cat = document.querySelector('meta[data-category]').content
fetch('https://nmns.place/track?' + new URLSearchParams({ fetch('https://nmns.place/track?' + new URLSearchParams({
hash: Cookies.get('nfcexplorer'), hash: Cookies.get('nfcexplorer'),
ua: ua, ua: ua,
})); cat: cat
})).then(response => {
progress = document.querySelector('span#progress').content
document.querySelector('span#progress').content = response
})
.catch(error => {
// handle the error
});

View file

@ -1,13 +1,20 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block head %}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta data-category="{{ article.category.slug }}" />
<link href="{{ SITEURL }}/theme/local.css" rel="stylesheet">
{% endblock head %}
{% block content %} {% block content %}
<section id="content" class="body"> <section id="content" class="body">
<div class="entry-content"> <div class="entry-content">
{{ article.content }} {{ article.content }}
{% if article.metadata.geohash %} {% if article.metadata.geohash %}
<a href="{{ SITEURL }}/{{ article.category.url }}">Map</a> <a href="{{ SITEURL }}/{{ article.category.url }}">Map</a>
{% endif %} <span id="progress">{% for cat, art in categories %}{% if cat.slug == category.slug %}{{ art|count }}{% endif %}{% endfor %}</span>
</div> {% endif %}
</section> </div>
</section>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ SITEURL }}/theme/user.js"></script> <script src="{{ SITEURL }}/theme/user.js"></script>

View file

@ -1,25 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ DEFAULT_LANG }}"> <html lang="{{ DEFAULT_LANG }}">
<head> <head>
<title>{% block title %}{{ SITENAME }}{% endblock title %}</title> <title>{% block title %}{{ SITENAME }}{% endblock title %}</title>
{% block head %} {% block head %}
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="{{ SITEURL }}/theme/local.css" rel="stylesheet"> <link href="{{ SITEURL }}/theme/local.css" rel="stylesheet">
{% endblock head %} {% endblock head %}
</head> </head>
<body id="index" class="home"> <body id="index" class="home">
{% block content %} {% block content %}
{% endblock %} {% endblock %}
{% if DESCRIPTION %} {% if DESCRIPTION %}
<footer id="contentinfo" class="body"> <footer id="contentinfo" class="body">
<hr> <hr>
{{ DESCRIPTION }} {{ DESCRIPTION }}
</footer> </footer>
{% endif %} {% endif %}
</body> </body>
{% block scripts %} {% block scripts %}
<script src="{{ SITEURL }}/theme/platform.js"></script> <script src="{{ SITEURL }}/theme/platform.js"></script>

View file

@ -52,10 +52,10 @@ PAGE_PATHS = ['pages',]
SUMMARY_MAX_LENGTH = 0 SUMMARY_MAX_LENGTH = 0
DEFAULT_DATE_FORMAT = '%Y-%m-%d' DEFAULT_DATE_FORMAT = '%Y-%m-%d'
DEFAULT_CATEGORY = 'tag' DEFAULT_CATEGORY = 'ad-hoc'
CATEGORIES_SAVE_AS = 'projects/index.html' CATEGORIES_SAVE_AS = 'zones/index.html'
CATEGORY_URL = 'projects/{slug}' CATEGORY_URL = 'zone/{slug}'
CATEGORY_SAVE_AS = 'projects/{slug}/index.html' CATEGORY_SAVE_AS = 'zone/{slug}/index.html'
DELETE_OUTPUT_DIRECTORY = True DELETE_OUTPUT_DIRECTORY = True

View file

@ -33,7 +33,7 @@ def makeKML():
point.appendChild( coordinates ) point.appendChild( coordinates )
placemark.appendChild( point ) placemark.appendChild( point )
root.childNodes[0].childNodes[0].childNodes[0].appendChild( placemark ) 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') root.writexml(xml_file, indent="", addindent=" ", newl='\n')
def makeGPX(): def makeGPX():
@ -50,10 +50,12 @@ def makeGPX():
name.appendChild( title ) name.appendChild( title )
wpt.appendChild( name ) wpt.appendChild( name )
root.childNodes[0].appendChild( wpt ) 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') root.writexml(xml_file, indent="", addindent=" ", newl='\n')
def geodata(generator): def geodata(generator):
output = generator.settings.get('OUTPUT_PATH')
filepath = generator.settings.get('CATEGORY_URL')
for category, articles in generator.categories: for category, articles in generator.categories:
locations = [] locations = []
for article in articles: for article in articles:
@ -65,6 +67,7 @@ def geodata(generator):
collection.update({ collection.update({
category.slug : { category.slug : {
"name" : category.name, "name" : category.name,
"path" : output + '/' + filepath.replace('{slug}', category.slug),
"points" : locations "points" : locations
}}) }})