From 5765687f9ddce136d19b460fa3b2cb19ad48e58d Mon Sep 17 00:00:00 2001 From: Krateng Date: Fri, 29 Mar 2019 19:44:42 +0100 Subject: [PATCH] Moved logging and timing to doreah --- database.py | 1 + doreah/logging.py | 102 +++++++++++++++++++++++++++++++++++ doreah/persistence.py | 40 ++++++++++++++ doreah/timing.py | 44 +++++++++++++++ doreah/tsv.py | 115 ++++++++++++++++++++++++++++++++++++++++ fixexisting.py | 18 +++---- lastfmconverter.py | 37 ++++++------- server.py | 1 + utilities.py | 36 +++++++------ website/artist.html | 10 ++-- website/artist.py | 14 ++--- website/issues.py | 6 +-- website/pulse.html | 6 +-- website/pulse.py | 35 ++++++------ website/scrobbles.html | 6 +-- website/scrobbles.py | 29 +++++----- website/start.html | 96 ++++++++++++++++----------------- website/start.py | 12 ++--- website/topartists.html | 10 ++-- website/topartists.py | 16 +++--- website/toptracks.html | 10 ++-- website/toptracks.py | 25 +++++---- website/track.html | 18 +++---- website/track.py | 18 +++---- website/wait.html | 22 ++++---- 25 files changed, 513 insertions(+), 214 deletions(-) create mode 100644 doreah/logging.py create mode 100644 doreah/persistence.py create mode 100644 doreah/timing.py create mode 100644 doreah/tsv.py diff --git a/database.py b/database.py index 46ad883..3d51ba7 100644 --- a/database.py +++ b/database.py @@ -6,6 +6,7 @@ import os import datetime from cleanup import * from utilities import * +from doreah.logging import log from malojatime import * import sys import unicodedata diff --git a/doreah/logging.py b/doreah/logging.py new file mode 100644 index 0000000..183ded0 --- /dev/null +++ b/doreah/logging.py @@ -0,0 +1,102 @@ +import datetime +import inspect +import os + +from ._internal import defaultarguments, gopen + +_config = {} + +_queue = [] +_locked = False + +# set configuration +# logfolder folder to store logfiles in +# timeformat strftime format for log files +# defaultmodule name for the main running script +# verbosity higher means more (less important) messages are shown on console +def config(logfolder="logs",timeformat="%Y/%m/%d %H:%M:%S",defaultmodule="main",verbosity=0): + global _config + _config["logfolder"] = logfolder + _config["timeformat"] = timeformat + _config["defaultmodule"] = defaultmodule + _config["verbosity"] = verbosity + + +# initial config on import, set everything to default +config() + + + + + +# Log entry +# module allows discrimination between modules of a program. Will be prepended in console output and will determine the separate file for disk storage +# defaults to actual name of the calling module or "main" for the main script +# header determines the hierarchical position of the entry. +# indent adds indent to the log entry +# importance low means important. if higher than the configured verbosity, entry will not be shown on console +def log(*msgs,module=None,header=None,indent=0,importance=0): + + now = datetime.datetime.utcnow().strftime(_config["timeformat"]) + + # log() can be used to add empty line + if len(msgs) == 0: msgs = ("",) + + # make it easier to log data structures and such + msgs = tuple([str(msg) for msg in msgs]) + + # header formating + if header == 2: + msgs = ("","","####") + msgs + ("####","") + elif header == 1: + msgs = ("","","","# # # # #","") + msgs + ("","# # # # #","","") + + # indent + prefix = "\t" * indent + + # module name + if module is None: + try: + module = inspect.getmodule(inspect.stack()[1][0]).__name__ + if module == "__main__": module = _config["defaultmodule"] + except: + module = "interpreter" + + global _locked, _queue + if _locked: + for msg in msgs: + _queue.append({"time":now,"prefix":prefix,"msg":msg,"module":module,"console":(importance <= _config["verbosity"])}) + else: + # console output + if (importance <= _config["verbosity"]): + for msg in msgs: + print("[" + module + "] " + prefix + msg) + + # file output + logfilename = _config["logfolder"] + "/" + module + ".log" + #os.makedirs(os.path.dirname(logfilename), exist_ok=True) + with gopen(logfilename,"a") as logfile: + for msg in msgs: + logfile.write(now + " " + prefix + msg + "\n") + + +def flush(): + global _queue + for entry in _queue: + # console output + if entry["console"]: + print("[" + entry["module"] + "] " + entry["prefix"] + entry["msg"]) + + # file output + logfilename = _config["logfolder"] + "/" + entry["module"] + ".log" + #os.makedirs(os.path.dirname(logfilename), exist_ok=True) + with gopen(logfilename,"a") as logfile: + logfile.write(entry["time"] + " " + entry["prefix"] + entry["msg"] + "\n") + + _queue = [] + +# Quicker way to add header +def logh1(*args,**kwargs): + return log(*args,**kwargs,header=1) +def logh2(*args,**kwargs): + return log(*args,**kwargs,header=2) diff --git a/doreah/persistence.py b/doreah/persistence.py new file mode 100644 index 0000000..1c10363 --- /dev/null +++ b/doreah/persistence.py @@ -0,0 +1,40 @@ +import pickle +import os + +from ._internal import defaultarguments, gopen + +_config = {} + +# set configuration +# folder folder to store log files +def config(folder="storage"): + global _config + _config["folder"] = folder + + +# initial config on import, set everything to default +config() + +@defaultarguments(_config,folder="folder") +def save(data,name,folder): + + filename = os.path.join(folder,name + ".gilly") + + fl = gopen(filename,"wb") + stream = pickle.dumps(data) + fl.write(stream) + fl.close() + +@defaultarguments(_config,folder="folder") +def load(name,folder): + + filename = os.path.join(folder,name + ".gilly") + + try: + fl = gopen(filename,"rb") + ob = pickle.loads(fl.read()) + except: ob = None + finally: + fl.close() + + return ob diff --git a/doreah/timing.py b/doreah/timing.py new file mode 100644 index 0000000..26fb862 --- /dev/null +++ b/doreah/timing.py @@ -0,0 +1,44 @@ +import time + +from ._internal import defaultarguments + +_config = {} + + +# set configuration +# si 0 means seconds, 1 ms, 2 μs, 3 ns etc +def config(si=0): + global _config + _config["si"] = si + + +# initial config on import, set everything to default +config() + + +# Take clock. Returns time passed since last call of this function. if called with an identifier, will only +# consider calls with that identifier. No identifier means any call is valid. +# identifiers arbitrary strings to remember different timers. guaranteed to set all timers to exactly the same time for +# all identifiers in one call. will return tuple of all identifiers, singular value if only one identifier +def clock(*identifiers,lastcalls={None:None}): + + if len(identifiers) == 0: identifiers = (None,) + + now = time.time() + # get last calls + stamps = (lastcalls.get(i) for i in identifiers) + results = tuple(None if lc is None else (now - lc) * (1000**_config["si"]) for lc in stamps) + if len(results) == 1: results = results[0] + + # set new stamps + for i in identifiers: + lastcalls[i] = now + lastcalls[None] = now # always save last overall call so we can directly access it + + return results + + + +def clockp(name,*identifiers): + time = clock(*identifiers) + print(name + ": " + str(time)) diff --git a/doreah/tsv.py b/doreah/tsv.py new file mode 100644 index 0000000..739154e --- /dev/null +++ b/doreah/tsv.py @@ -0,0 +1,115 @@ +import os + +from ._internal import defaultarguments + +_config = {} + +# set configuration +# defaultextension files with this extension will be regarded as valid files. can be overwritten per request. +# comments whether files may include commenting (indicated by #) +# multitab whether fields can be separated by multiple tabs (this makes empty fields impossible except when trailing) +def config(defaultextension=".tsv",comments=True,multitab=True): + global _config + _config["defaultextension"] = defaultextension + _config["comments"] = comments + _config["multitab"] = multitab + + +# initial config on import, set everything to default +config() + + +@defaultarguments(_config,comments="comments",multitab="multitab") +def parse(filename,*args,comments,multitab): + + if not os.path.exists(filename): + filename = filename + _config["defaultextension"] + + f = open(filename) + + result = [] + for l in [l for l in f if (not l.startswith("#")) and (not l.strip()=="")]: + l = l.replace("\n","") + + # if the file allows comments, we need to replace the escape sequence and properly stop parsing for inline comments + if comments: + l = l.split("#")[0] + l = l.replace(r"\num","#") + l = l.replace(r"\hashtag","#") + + # we either allow multiple tabs, or we don't (in which case empty fields are possible) + if multitab: + data = list(filter(None,l.split("\t"))) + else: + data = list(l.split("\t")) + + entry = [] * len(args) + for i in range(len(args)): + if args[i] in ["list","ls","array"]: + try: + entry.append(data[i].split("␟")) + except: + entry.append([]) + elif args[i] in ["string","str","text"]: + try: + entry.append(data[i]) + except: + entry.append("") + elif args[i] in ["int","integer","num","number"]: + try: + entry.append(int(data[i])) + except: + entry.append(0) + elif args[i] in ["bool","boolean"]: + try: + entry.append((data[i].lower() in ["true","yes","1","y"])) + except: + entry.append(False) + else: + raise TypeError() + + result.append(entry) + + f.close() + return result + +@defaultarguments(_config,extension="defaultextension") +def parse_all(path,*args,extension,**kwargs): + + result = [] + for f in os.listdir(path + "/"): + if (f.endswith(extension)): # use "" if all files are valid + result += parse(path + "/" + f,*args,**kwargs) + + return result + + + +def create(filename): + + if not os.path.exists(filename): + open(filename,"w").close() + +@defaultarguments(_config,comments="comments") +def add_entry(filename,a,comments): + + create(filename) + # remove all tabs and create tab-separated string + line = "\t".join([str(e).replace("\t"," ") for e in a]) + + # replace comment symbol + if comments: line = line.replace("#",r"\num") + + with open(filename,"a") as f: + f.write(line + "\n") + +@defaultarguments(_config,comments="comments") +def add_entries(filename,al,comments): + + create(filename) + + with open(filename,"a") as f: + for a in al: + line = "\t".join([str(e).replace("\t"," ") for e in a]) + if comments: line = line.replace("#",r"\num") + f.write(line + "\n") diff --git a/fixexisting.py b/fixexisting.py index d653b4a..5c4538e 100644 --- a/fixexisting.py +++ b/fixexisting.py @@ -1,7 +1,7 @@ import os import re from cleanup import CleanerAgent -from utilities import log +from doreah.logging import log import difflib wendigo = CleanerAgent() @@ -13,34 +13,34 @@ for fn in os.listdir("scrobbles/"): f = open("scrobbles/" + fn) fnew = open("scrobbles/" + fn + "_new","w") for l in f: - + a,t = re.sub(exp,r"\3",l), re.sub(exp,r"\5",l) r1,r2,r3 = re.sub(exp,r"\1\2",l),re.sub(exp,r"\4",l),re.sub(exp,r"\6\7",l) - + a = a.replace("␟",";") - + (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) #print("2: " + r2) #print("3: " + r3) - + f.close() fnew.close() - + #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) - + checkfile = open("scrobbles/" + fn + ".rulestate","w") checkfile.write(wendigo.checksums) checkfile.close() diff --git a/lastfmconverter.py b/lastfmconverter.py index 755632c..162234b 100644 --- a/lastfmconverter.py +++ b/lastfmconverter.py @@ -14,26 +14,26 @@ stamps = [99999999999999] for l in log: l = l.replace("\n","") data = l.split(",") - + artist = data[0] album = data[1] title = data[2] time = data[3] - - + + (artists,title) = c.fullclean(artist,title) - + artistsstr = "␟".join(artists) - - + + timeparts = time.split(" ") (h,m) = timeparts[3].split(":") - + months = {"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12} - + timestamp = int(datetime.datetime(int(timeparts[2]),months[timeparts[1]],int(timeparts[0]),int(h),int(m)).timestamp()) - - + + ## We prevent double timestamps in the database creation, so we technically don't need them in the files ## however since the conversion from lastfm to maloja is a one-time thing, we should take any effort to make the file as good as possible if (timestamp < stamps[-1]): @@ -43,24 +43,21 @@ for l in log: else: while(timestamp in stamps): timestamp -= 1 - - if (timestamp < stamps[-1]): + + if (timestamp < stamps[-1]): stamps.append(timestamp) else: stamps.insert(0,timestamp) - - + + entry = "\t".join([str(timestamp),artistsstr,title,album]) entry = entry.replace("#",r"\num") - + outputlog.write(entry) outputlog.write("\n") - + checksumfile.write(c.checksums) - + log.close() outputlog.close() checksumfile.close() - - - diff --git a/server.py b/server.py index 14e59a5..acb264b 100755 --- a/server.py +++ b/server.py @@ -10,6 +10,7 @@ from utilities import * from htmlgenerators import KeySplit # doreah toolkit from doreah import settings +from doreah.logging import log # technical from importlib.machinery import SourceFileLoader import _thread diff --git a/utilities.py b/utilities.py index d7a7efb..ab858fc 100644 --- a/utilities.py +++ b/utilities.py @@ -164,27 +164,29 @@ def addEntries(filename,al,escape=True): ### Logging +# now handled by doreah -def log(msg,module=None): - now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") - 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") +#def log(msg,module=None): +# now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") +# 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") ### not meant to be precise, just for a rough idea -measurement = 0 -def clock(*args): - import time - global measurement - now = time.time() - if len(args) > 0: - print(args[0] + ": " + str(now - measurement)) - measurement = now +# now handled by doreah +#measurement = 0 +#def clock(*args): +# import time +# global measurement +# now = time.time() +# if len(args) > 0: +# print(args[0] + ": " + str(now - measurement)) +# measurement = now diff --git a/website/artist.html b/website/artist.html index c563d2e..7546f66 100644 --- a/website/artist.html +++ b/website/artist.html @@ -5,7 +5,7 @@ Maloja - KEY_ARTISTNAME - + @@ -16,18 +16,18 @@

KEY_ARTISTNAME

KEY_POSITION
KEY_ASSOCIATED

KEY_SCROBBLES Scrobbles

- +

KEY_DESCRIPTION

- +

Top Tracks

KEY_TRACKLIST - +

Pulse

KEY_PULSE - + diff --git a/website/artist.py b/website/artist.py index cc789f7..3dd5994 100644 --- a/website/artist.py +++ b/website/artist.py @@ -1,7 +1,7 @@ import urllib import database - + def instructions(keys): from utilities import getArtistImage from htmlgenerators import artistLink, artistLinks, KeySplit @@ -10,11 +10,11 @@ def instructions(keys): filterkeys, _, _, _ = KeySplit(keys,forceArtist=True) imgurl = getArtistImage(filterkeys["artist"],fast=True) pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - + data = database.artistInfo(filterkeys["artist"]) scrobbles = str(data["scrobbles"]) pos = "#" + str(data["position"]) - + credited = data.get("replace") includestr = " " if credited is not None: @@ -24,11 +24,11 @@ def instructions(keys): if included is not None and included != []: includestr = "associated: " includestr += artistLinks(included) + + + html_tracks, _ = module_trackcharts(**filterkeys,max_=15) - html_tracks, _ = module_trackcharts(**filterkeys,max_=15) - - html_pulse = module_pulse(**filterkeys,step="year",stepn=1,trail=1) replace = {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]), @@ -36,5 +36,5 @@ def instructions(keys): "KEY_TRACKLIST":html_tracks,"KEY_PULSE":html_pulse, "KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos, "KEY_ASSOCIATED":includestr} - + return (replace,pushresources) diff --git a/website/issues.py b/website/issues.py index bed56a6..d389ad0 100644 --- a/website/issues.py +++ b/website/issues.py @@ -3,10 +3,10 @@ import database from htmlgenerators import artistLink def instructions(keys): - + db_data = database.issues() i = 0 - + html = "" if db_data["inconsistent"]: html += "" @@ -38,7 +38,7 @@ def instructions(keys): html += """""" html += "" i += 1 - + html += "
Yes
" return ({"KEY_ISSUESLIST":html,"KEY_ISSUES":str(i)},[]) diff --git a/website/pulse.html b/website/pulse.html index 57ff21b..96bf85f 100644 --- a/website/pulse.html +++ b/website/pulse.html @@ -5,7 +5,7 @@ Maloja - KEY_PULSEDETAILS Pulse - + @@ -20,8 +20,8 @@
- + KEY_PULSE_TABLE - + diff --git a/website/pulse.py b/website/pulse.py index e509fcb..5e8fb10 100644 --- a/website/pulse.py +++ b/website/pulse.py @@ -1,16 +1,16 @@ import urllib import database - + def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink, keysToUrl, KeySplit - from htmlmodules import module_pulse + from htmlmodules import module_pulse from malojatime import range_desc, delimit_desc - + filterkeys, timekeys, delimitkeys, _ = KeySplit(keys) - - + + # describe the scope (and creating a key for the relevant artist or track) limitstring = "" #limitkey = {} @@ -18,7 +18,7 @@ def instructions(keys): #limitkey["track"] = {"artists":keys.getall("artist"),"title":keys.get("title")} limitstring += "of " + trackLink(filterkeys["track"]) + " " limitstring += "by " + artistLinks(filterkeys["track"]["artists"]) - + elif filterkeys.get("artist") is not None: #limitkey["artist"], limitkey["associated"] = keys.get("artist"), (keys.get("associated")!=None) limitstring += "of " + artistLink(filterkeys.get("artist")) @@ -27,27 +27,26 @@ def instructions(keys): moreartists = data["associated"] if moreartists != []: limitstring += " including " + artistLinks(moreartists) + "" - + limitstring += " " + range_desc(**timekeys) - + delimitstring = delimit_desc(**delimitkeys) - - - # get image + + + # get image if filterkeys.get("track") is not None: imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"]) elif filterkeys.get("artist") is not None: imgurl = getArtistImage(keys.get("artist")) else: imgurl = "" - - pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - - + pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] + + + html_pulse = module_pulse(**filterkeys,**timekeys,**delimitkeys) - + replace = {"KEY_PULSE_TABLE":html_pulse,"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring,"KEY_PULSEDETAILS":delimitstring} - + return (replace,pushresources) - diff --git a/website/scrobbles.html b/website/scrobbles.html index 5b47c11..d9de45d 100644 --- a/website/scrobbles.html +++ b/website/scrobbles.html @@ -5,7 +5,7 @@ Maloja - Scrobbles - + @@ -20,8 +20,8 @@
- + KEY_SCROBBLELIST - + diff --git a/website/scrobbles.py b/website/scrobbles.py index c068b12..d5e8e9d 100644 --- a/website/scrobbles.py +++ b/website/scrobbles.py @@ -1,22 +1,22 @@ import urllib import database - + def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLink, artistLinks, trackLink, KeySplit - from htmlmodules import module_scrobblelist + from htmlmodules import module_scrobblelist from malojatime import range_desc - - + + filterkeys, timekeys, _, amountkeys = KeySplit(keys) - + # describe the scope limitstring = "" if filterkeys.get("track") is not None: limitstring += "of " + trackLink(filterkeys["track"]) + " " limitstring += "by " + artistLinks(filterkeys["track"]["artists"]) - + elif filterkeys.get("artist") is not None: limitstring += "by " + artistLink(filterkeys.get("artist")) if filterkeys.get("associated"): @@ -24,13 +24,13 @@ def instructions(keys): moreartists = data.get("associated") if moreartists != []: limitstring += " including " + artistLinks(moreartists) + "" - + limitstring += " " + range_desc(**timekeys) - + html, amount, rep = module_scrobblelist(**filterkeys,**timekeys,**amountkeys) - - # get image + + # get image if filterkeys.get("track") is not None: imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"],fast=True) elif filterkeys.get("artist") is not None: @@ -39,12 +39,11 @@ def instructions(keys): imgurl = getTrackImage(rep["artists"],rep["title"],fast=True) else: imgurl = "" - - + + pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - + replace = {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(amount),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring} - + return (replace,pushresources) - diff --git a/website/start.html b/website/start.html index 7f105d7..166ce5e 100644 --- a/website/start.html +++ b/website/start.html @@ -4,9 +4,9 @@ Maloja - - - + + + - - - + + + - + - - + +

Top Artists

- - - + + + This Week | This Month - | This Year + | This Year | All Time - +

- + KEY_TOPARTISTS_TOTAL - - - - + + + +

Top Tracks

- - + + This Week | This Month - | This Year + | This Year | All Time - +

- + KEY_TOPTRACKS_TOTAL - - - - - - + + + + + +

Last Scrobbles

Today KEY_SCROBBLE_NUM_TODAY @@ -79,34 +79,34 @@ This year KEY_SCROBBLE_NUM_YEAR All Time KEY_SCROBBLE_NUM_TOTAL

- + KEY_SCROBBLES - - + +
- - + +

Pulse

- - + 7 days | 12 weeks - | 12 months + | 12 months | 10 years

- + KEY_PULSE_MONTHS @@ -117,9 +117,9 @@ -->
- - - + + + - + diff --git a/website/start.py b/website/start.py index eaa6c4f..d7c4fde 100644 --- a/website/start.py +++ b/website/start.py @@ -1,7 +1,7 @@ import urllib from datetime import datetime, timedelta import database -from utilities import clock +from doreah.timing import clock, clockp from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles @@ -24,7 +24,7 @@ def instructions(keys): topartists_month = module_artistcharts_tiles(since="month") topartists_week = module_artistcharts_tiles(since=weekstart) - clock("Artists") + clockp("Artists") # tracks @@ -34,13 +34,13 @@ def instructions(keys): toptracks_week = module_trackcharts_tiles(since=weekstart) - clock("Tracks") + clockp("Tracks") # scrobbles html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True) - clock("Scrobbles") + clockp("Scrobbles") # stats @@ -61,7 +61,7 @@ def instructions(keys): amount_total = database.get_scrobbles_num() scrobbles_total = "" + str(amount_total) + "" - clock("Amounts") + clockp("Amounts") # pulse dt = datetime.utcnow() @@ -83,7 +83,7 @@ def instructions(keys): #html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1) #html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1) - clock("Pulse") + clockp("Pulse") #pushresources = [{"file":img,"type":"image"} for img in artistimages + trackimages] #can't push scrobble images as we don't get them from the module function, need to think about that pushresources = [] diff --git a/website/topartists.html b/website/topartists.html index e97dc17..4af64d7 100644 --- a/website/topartists.html +++ b/website/topartists.html @@ -5,7 +5,7 @@ Maloja - Top Artists - + @@ -16,13 +16,13 @@

Top Artists


KEY_RANGE - +
- - + + KEY_ARTISTLIST - + diff --git a/website/topartists.py b/website/topartists.py index c4cc2dd..2af4bfb 100644 --- a/website/topartists.py +++ b/website/topartists.py @@ -1,28 +1,28 @@ import urllib - + def instructions(keys): from utilities import getArtistImage from htmlgenerators import KeySplit from htmlmodules import module_artistcharts from malojatime import range_desc - + _, timekeys, _, amountkeys = KeySplit(keys) - + limitstring = range_desc(**timekeys) + - - + html_charts, rep = module_artistcharts(**amountkeys,**timekeys) - + if rep is not None: imgurl = getArtistImage(rep) else: imgurl = "" - + pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - + replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_ARTISTLIST":html_charts,"KEY_RANGE":limitstring} diff --git a/website/toptracks.html b/website/toptracks.html index 272840e..61fb06c 100644 --- a/website/toptracks.html +++ b/website/toptracks.html @@ -5,7 +5,7 @@ Maloja - Top Tracks - + @@ -16,13 +16,13 @@

Top Tracks


KEY_LIMITS - +
- - + + KEY_TRACKLIST - + diff --git a/website/toptracks.py b/website/toptracks.py index ef5bbea..8074e1e 100644 --- a/website/toptracks.py +++ b/website/toptracks.py @@ -1,36 +1,35 @@ import urllib - + def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLink, KeySplit - from htmlmodules import module_trackcharts + from htmlmodules import module_trackcharts from malojatime import range_desc - + filterkeys, timekeys, _, amountkeys = KeySplit(keys) - + limitstring = "" - + html_charts, rep = module_trackcharts(**amountkeys,**timekeys,**filterkeys) - - + + if filterkeys.get("artist") is not None: imgurl = getArtistImage(filterkeys.get("artist")) limitstring = "by " + artistLink(filterkeys.get("artist")) elif rep is not None: - imgurl = getTrackImage(rep["artists"],rep["title"]) + imgurl = getTrackImage(rep["artists"],rep["title"]) else: imgurl = "" - + limitstring += " " + range_desc(**timekeys) - + pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - + replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_TRACKLIST":html_charts,"KEY_LIMITS":limitstring} - - return (replace,pushresources) + return (replace,pushresources) diff --git a/website/track.html b/website/track.html index 7880905..79cca09 100644 --- a/website/track.html +++ b/website/track.html @@ -5,7 +5,7 @@ Maloja - KEY_TRACKTITLE - + @@ -15,22 +15,22 @@
KEY_ARTISTS

KEY_TRACKTITLE

KEY_POSITION - +

KEY_SCROBBLES Scrobbles

- +

- +

Pulse

KEY_PULSE - - + +

Scrobbles

KEY_SCROBBLELIST - - - + + + diff --git a/website/track.py b/website/track.py index eb295b5..e1a14b2 100644 --- a/website/track.py +++ b/website/track.py @@ -1,32 +1,32 @@ import urllib import database - + def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLinks, keysToUrl, KeySplit from htmlmodules import module_scrobblelist, module_pulse - - filterkeys, _, _, _ = KeySplit(keys,forceTrack=True) - + + filterkeys, _, _, _ = KeySplit(keys,forceTrack=True) + track = filterkeys.get("track") imgurl = getTrackImage(track["artists"],track["title"],fast=True) pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - + data = database.trackInfo(track["artists"],track["title"]) - + scrobblesnum = str(data["scrobbles"]) pos = "#" + str(data["position"]) - + html_scrobbles, _, _ = module_scrobblelist(track=track,max_=100,earlystop=True) # we have the number already from the trackinfo - + html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1) replace = {"KEY_TRACKTITLE":track.get("title"),"KEY_ARTISTS":artistLinks(track.get("artists")),"KEY_SCROBBLES":scrobblesnum,"KEY_POSITION":pos,"KEY_IMAGEURL":imgurl, "KEY_SCROBBLELINK":keysToUrl(keys), "KEY_SCROBBLELIST":html_scrobbles,"KEY_PULSE":html_pulse} - + return (replace,pushresources) diff --git a/website/wait.html b/website/wait.html index d961a55..d6b847a 100644 --- a/website/wait.html +++ b/website/wait.html @@ -5,27 +5,27 @@ Maloja - Please wait - + - +

Maloja


Redbuilding the database - +

Please wait...

- - + + - +