diff --git a/database.py b/database.py index e38cad8..2c27650 100644 --- a/database.py +++ b/database.py @@ -118,6 +118,7 @@ def test_server(): def get_scrobbles(): keys = request.query r = db_query(artist=keys.get("artist"),track=keys.get("track"),since=keys.get("since"),to=keys.get("to")) + r.reverse() return {"list":r} ##json can't be a list apparently??? @@ -427,6 +428,8 @@ def build_db(): readScrobble(artists,title,time) + SCROBBLES.sort(key = lambda tup: tup[1]) + diff --git a/utilities.py b/utilities.py index 06331da..7bae2c3 100644 --- a/utilities.py +++ b/utilities.py @@ -147,3 +147,10 @@ def cacheImage(url,path,filename): response = urllib.request.urlopen(url) target = path + "/" + filename + "." + response.info().get_content_subtype() urllib.request.urlretrieve(url,target) + + + +def getTimeDesc(timestamp): + import datetime + tim = datetime.datetime.utcfromtimestamp(timestamp) + return tim.strftime("%d. %b %Y %I:%M %p") diff --git a/website/scrobbles.py b/website/scrobbles.py new file mode 100644 index 0000000..a10fc02 --- /dev/null +++ b/website/scrobbles.py @@ -0,0 +1,41 @@ +import urllib +import json + + +def replacedict(keys,dbport): + from utilities import getArtistInfo, getTimeDesc + + + #hand down the since and from arguments + extrakeys = urllib.parse.urlencode(keys) + + if keys.get("artist") is not None: + info = getArtistInfo(keys.get("artist")) + imgurl = info.get("image") + else: + imgurl = "" #for now + + limitstring = "" + if keys.get("artist") is not None: + limitstring += "by " + keys.get("artist") + " " + + + response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys) + db_data = json.loads(response.read()) + scrobbles = db_data["list"] + + html = "
" + timestring = getTimeDesc(s["time"]) + html += timestring + html += " | " + artisthtml = "" + for a in s["artists"]: + artisthtml += "" + a + ", " + html += artisthtml[:-2] + html += " | " + s["title"] + " |