List_server_busy/www/archive.py
gauthiier 46a0cc8c0b www
2019-12-08 21:42:16 +01:00

58 lines
854 B
Python

import os, glob, json
ARCH = "archives/"
EXP = "selection/"
sel = os.path.join(EXP, "tm-selection.js")
with open(sel) as f:
d = json.load(f)
def lists():
return os.listdir(ARCH)
def tags():
global d
return list(d.keys())
def commit(li, url, tag):
global sel
if tag not in list(d.keys()):
print("new tag: " + tag)
d[tag] = []
for i in d[tag]:
if i['url'] == url:
return False
d[tag].append({'list': li, 'url': url})
with open(sel, 'w', encoding='utf-8') as f:
json.dump(d, f, ensure_ascii=False, indent=4)
return True
def report():
re = "Report: \n"
for k, v in d.items():
lre = {}
for i in v:
if i['list'] not in lre:
lre[i['list']] = 0
lre[i['list']] += 1
re += "<" + k + ">: " + str(len(v)) + " ("
for kk, vv in lre.items():
re += kk + ": " + str(vv) + " / "
re += ")\n"
return re