diff --git a/database.py b/database.py index ee092bd..868e56d 100644 --- a/database.py +++ b/database.py @@ -329,7 +329,7 @@ def artistInfo(): artist = keys.get("artist") charts = db_aggregate(by="ARTIST") - scrobbles = len(db_query(artist=artist)) #we cant take the scrobble number from the charts because that includes all countas scrobbles + scrobbles = len(db_query(artists=[artist])) #we cant take the scrobble number from the charts because that includes all countas scrobbles try: c = [e for e in charts if e["artist"] == artist][0] others = coa.getAllAssociated(artist) diff --git a/server.py b/server.py index 4d7ccc4..0220ac4 100755 --- a/server.py +++ b/server.py @@ -2,6 +2,7 @@ from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict from importlib.machinery import SourceFileLoader +from utilities import removeIdentical import _thread import waitress import urllib.request @@ -89,7 +90,8 @@ def static(name): @webserver.route("/") def static_html(name): - keys = FormsDict.decode(request.query) + + keys = removeIdentical(FormsDict.decode(request.query)) # If a python file exists, it provides the replacement dict for the html file if os.path.exists("website/" + name + ".py"): diff --git a/utilities.py b/utilities.py index 9950c05..853b056 100644 --- a/utilities.py +++ b/utilities.py @@ -231,7 +231,27 @@ def cacheImage(url,path,filename): def artistLink(name): import urllib return "" + name + "" + +# necessary because urllib.parse.urlencode doesnt handle multidicts +def keysToUrl(keys): + import urllib + st = "" + for k in removeIdentical(keys): + values = keys.getall(k) + st += "&".join([urllib.parse.urlencode({k:v}) for v in values]) + st += "&" + return st +def removeIdentical(keys): + from bottle import FormsDict + + new = FormsDict() + for k in keys: + values = set(keys.getall(k)) + for v in values: + new.append(k,v) + + return new def getTimeDesc(timestamp): import datetime diff --git a/website/scrobbles.py b/website/scrobbles.py index 90157dc..ac4ecd8 100644 --- a/website/scrobbles.py +++ b/website/scrobbles.py @@ -3,23 +3,27 @@ import json def replacedict(keys,dbport): - from utilities import getArtistInfo, getTimeDesc, artistLink + from utilities import getArtistInfo, getTimeDesc, artistLink, keysToUrl #hand down the since and from arguments - extrakeys = urllib.parse.urlencode(keys) - - - + #extrakeys = urllib.parse.urlencode(keys,doseq=True) + extrakeys = keysToUrl(keys) + limitstring = "" response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys) db_data = json.loads(response.read()) scrobbles = db_data["list"] - if keys.get("artist") is not None: + if keys.get("title") is not None: + limitstring += "of " + keys.get("title") + " " + limitstring += "by " + ", ".join([artistLink(a) for a in keys.getall("artist")]) latestartist = keys.get("artist") - limitstring += "by " + artistLink(keys.get("artist")) + + elif keys.get("artist") is not None: + latestartist = keys.get("artist") + limitstring += "by " + artistLink(keys.get("artist")) #if we dont specifiy a title, we filter by one artist, which means only one artist is allowed if keys.get("associated") is not None: response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"])) db_data = json.loads(response.read()) diff --git a/website/toptracks.py b/website/toptracks.py index c56e351..076094e 100644 --- a/website/toptracks.py +++ b/website/toptracks.py @@ -3,13 +3,16 @@ import json def replacedict(keys,dbport): - from utilities import getArtistInfo, artistLink + from utilities import getArtistInfo, artistLink, keysToUrl # we don't use the associated key for top tracks so we don't wanna hand it down to functions we're calling keys.pop("associated",None) #hand down the since and from arguments extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/") + # I should probably add a separate variable for keys that are passed to db functions and keys that are inherited to links (usually only time) + #extrakeys = keysToUrl(keys) + # top tracks should always be of one artist response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + extrakeys) db_data = json.loads(response.read()) @@ -18,8 +21,8 @@ def replacedict(keys,dbport): if keys.get("artist") is not None: topartist = keys.get("artist") - limitstring += "by " + artistLink(keys.get("artist")) - + #limitstring += "by " + ", ".join([artistLink(a) for a in keys.getall("artist")]) + limitstring = "by " + artistLink(keys.get("artist")) else: topartist = charts[0]["track"]["artists"][0] #for now @@ -42,8 +45,8 @@ def replacedict(keys,dbport): html += "#" + str(i) + "" html += ", ".join([artistLink(a) for a in e["track"]["artists"]]) html += "" + e["track"]["title"] - html += "" + str(e["scrobbles"]) + "" - html += "
" + html += "" + str(e["scrobbles"]) + "" + html += "
" html += "" html += "" i += 1