From 709f3c129c8fbb1cb0238c4255fcaa22cba5dd9d Mon Sep 17 00:00:00 2001 From: Krateng Date: Sun, 10 Mar 2019 20:05:38 +0100 Subject: [PATCH] More logging --- database.py | 9 ++++++++- fixexisting.py | 10 +++++++++- utilities.py | 9 +++++---- website/maloja.css | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/database.py b/database.py index c3bfdee..2e15a9f 100644 --- a/database.py +++ b/database.py @@ -35,6 +35,7 @@ def loadAPIkeys(): global clients createTSV("clients/authenticated_machines.tsv") clients = parseTSV("clients/authenticated_machines.tsv","string","string") + log(str(len(clients)) + " Authenticated Machines " + ", ".join([m[1] for m in clients])) def checkAPIkey(k): return (k in [k for [k,d] in clients]) @@ -621,9 +622,11 @@ def issues(): @dbserver.post("/rebuild") def rebuild(): + keys = FormsDict.decode(request.forms) apikey = keys.pop("key",None) if (checkAPIkey(apikey)): + log("Database rebuild initiated!") global db_rulestate db_rulestate = False sync() @@ -660,6 +663,7 @@ def search(): # Starts the server def runserver(PORT): + log("Starting database server...") global lastsync lastsync = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp()) build_db() @@ -668,11 +672,12 @@ def runserver(PORT): loadAPIkeys() run(dbserver, host='::', port=PORT, server='waitress') + log("Database server reachable!") def build_db(): - + log("Building database...") global SCROBBLES, ARTISTS, TRACKS @@ -706,6 +711,8 @@ def build_db(): # load cached images loadCache() + log("Database fully built!") + diff --git a/fixexisting.py b/fixexisting.py index b75208e..d653b4a 100644 --- a/fixexisting.py +++ b/fixexisting.py @@ -1,6 +1,8 @@ import os import re from cleanup import CleanerAgent +from utilities import log +import difflib wendigo = CleanerAgent() @@ -20,6 +22,7 @@ for fn in os.listdir("scrobbles/"): (al,t) = wendigo.fullclean(a,t) a = "␟".join(al) fnew.write(r1 + a + r2 + t + r3 + "\n") + #print("Artists: " + a) #print("Title: " + t) #print("1: " + r1) @@ -29,7 +32,12 @@ for fn in os.listdir("scrobbles/"): f.close() fnew.close() - os.system("diff " + "scrobbles/" + fn + "_new" + " " + "scrobbles/" + fn) + #os.system("diff " + "scrobbles/" + fn + "_new" + " " + "scrobbles/" + fn) + with open("scrobbles/" + fn + "_new","r") as newfile: + with open("scrobbles/" + fn,"r") as oldfile: + diff = difflib.unified_diff(oldfile.read().split("\n"),newfile.read().split("\n"),lineterm="") + diff = list(diff)[2:] + log("Diff for scrobbles/" + fn + "".join("\n\t" + d for d in diff),module="fixer") os.rename("scrobbles/" + fn + "_new","scrobbles/" + fn) diff --git a/utilities.py b/utilities.py index 96fa4cc..cccb00e 100644 --- a/utilities.py +++ b/utilities.py @@ -159,11 +159,12 @@ def cleandict(d): ### Logging -def log(msg): - import inspect +def log(msg,module=None): now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") - module = inspect.getmodule(inspect.stack()[1][0]).__name__ - if module == "__main__": module = "mainserver" + if module is None: + import inspect + module = inspect.getmodule(inspect.stack()[1][0]).__name__ + if module == "__main__": module = "mainserver" print("[" + module + "] " + msg) with open("logs/" + module + ".log","a") as logfile: logfile.write(now + " " + msg + "\n") diff --git a/website/maloja.css b/website/maloja.css index c1de9e0..1527cdc 100644 --- a/website/maloja.css +++ b/website/maloja.css @@ -5,6 +5,7 @@ body { color:beige; font-family:"Ubuntu"; padding:15px; + padding-bottom:35px; /** padding-top:45px; padding-bottom:25px;