diff --git a/database.py b/database.py
index 880d46b..2ef2b64 100644
--- a/database.py
+++ b/database.py
@@ -132,6 +132,10 @@ def test_server():
else:
response.status = 205
return
+
+ # 204 Database server is up and operational
+ # 205 Database server is up, but DB is not fully built or is inconsistent
+ # 403 Database server is up, but provided API key is not valid
@dbserver.route("/scrobbles")
def get_scrobbles():
diff --git a/htmlgenerators.py b/htmlgenerators.py
index 64cc6f5..4be75b7 100644
--- a/htmlgenerators.py
+++ b/htmlgenerators.py
@@ -15,13 +15,13 @@ def trackLink(track):
return "" + title + ""
#def scrobblesTrackLink(artists,title,timekeys,amount=None,pixels=None):
-def scrobblesTrackLink(track,timekeys,amount=None,pixels=None):
+def scrobblesTrackLink(track,timekeys,amount=None,percent=None):
artists,title = track["artists"],track["title"]
import urllib
inner = str(amount) if amount is not None else "
"
return "" + inner + ""
-def scrobblesArtistLink(artist,timekeys,amount=None,pixels=None,associated=False):
+def scrobblesArtistLink(artist,timekeys,amount=None,percent=None,associated=False):
import urllib
inner = str(amount) if amount is not None else ""
askey = "&associated" if associated else ""
diff --git a/website/artist.py b/website/artist.py
index 08f5aa8..4a9c529 100644
--- a/website/artist.py
+++ b/website/artist.py
@@ -4,9 +4,9 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo
- from htmlgenerators import artistLink
+ from htmlgenerators import clean, artistLink, artistLinks, trackLink, scrobblesTrackLink
-
+ clean(keys)
info = getArtistInfo(keys["artist"])
imgurl = info.get("image")
desc = info.get("info")
@@ -24,22 +24,7 @@ def replacedict(keys,dbport):
included = db_data.get("associated")
if included is not None and included != []:
includestr = "associated: "
- #for a in included:
- includestr += ", ".join([artistLink(a) for a in included]) #"" + a + ", "
- #includestr = includestr[:-2]
-
-# response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/tracks?artist=" + urllib.parse.quote(keys["artist"]))
-# db_data = json.loads(response.read())
-#
-# html = ""
-# for e in db_data["list"]:
-# html += ""
-# html += ""
-# links = [artistLink(a) for a in e["artists"]]
-# html += ", ".join(links)
-# html += " | " + e["title"] + " | "
-# html += "
"
-# html += "
"
+ includestr += artistLinks(included)
@@ -51,12 +36,10 @@ def replacedict(keys,dbport):
html = ""
for e in db_data["list"]:
html += ""
- html += ""
- links = [artistLink(a) for a in e["track"]["artists"]]
- html += ", ".join(links)
- html += " | " + e["track"]["title"] + " | "
- html += "" + str(e["scrobbles"]) + " | "
- html += " | "
+ html += "" + artistLinks(e["track"]["artists"]) + " | "
+ html += "" + trackLink(e["track"]) + " | "
+ html += "" + scrobblesTrackLink(e["track"],{},amount=e["scrobbles"]) + " | "
+ html += "" + scrobblesTrackLink(e["track"],{},pixels=e["scrobbles"]*100/maxbar) + " | "
html += "
"
html += "
"
diff --git a/website/scrobbles.py b/website/scrobbles.py
index 20d154d..4648b03 100644
--- a/website/scrobbles.py
+++ b/website/scrobbles.py
@@ -9,39 +9,45 @@ def replacedict(keys,dbport):
clean(keys)
timekeys = pickKeys(keys,"since","to","in")
limitkeys = pickKeys(keys,"artist","title","associated")
-
- limitstring = ""
+
+ # Get scrobble data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys,timekeys))
db_data = json.loads(response.read())
scrobbles = db_data["list"]
+ # describe the scope
+ limitstring = ""
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 += "of " + trackLink({"title":keys.get("title"),"artists":keys.getall("artist")}) + " "
+ limitstring += "by " + artistLinks(keys.getall("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
+ limitstring += "by " + artistLink(keys.get("artist"))
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())
- moreartists = [artistLink(a) for a in db_data["associated"]]
+ moreartists = db_data["associated"]
if moreartists != []:
- limitstring += " "
+ limitstring += " "
- else:
- latestartist = scrobbles[0]["artists"][0]
- info = getArtistInfo(latestartist)
- imgurl = info.get("image")
+ # get representative artist for image
+ if keys.get("artist") is not None:
+ imgurl = getArtistInfo(keys.get("artist")).get("image")
+ elif (len(scrobbles) != 0):
+ imgurl = getArtistInfo(scrobbles[0]["artists"][0]).get("image")
+ else:
+ imgurl = ""
+
+ # build list
html = ""
for s in scrobbles:
html += ""
html += "" + getTimeDesc(s["time"]) + " | "
html += "" + artistLinks(s["artists"]) + " | "
- html += "" + trackLink({"artists":s["artists"],"title":s["title"]}) + " |
"
+ html += "" + trackLink({"artists":s["artists"],"title":s["title"]}) + " | "
+ html += ""
html += "
"
return {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(len(scrobbles)),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
diff --git a/website/topartists.py b/website/topartists.py
index 03f951a..b718a20 100644
--- a/website/topartists.py
+++ b/website/topartists.py
@@ -10,6 +10,7 @@ def replacedict(keys,dbport):
timekeys = pickKeys(keys,"since","to","in")
limitkeys = pickKeys(keys)
+ # get chart data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
charts = db_data["list"][:50]
@@ -18,13 +19,14 @@ def replacedict(keys,dbport):
info = getArtistInfo(topartist)
imgurl = info.get("image")
-
+ # get total amount of scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)
+ # build list
maxbar = charts[0]["scrobbles"]
i = 1
@@ -37,7 +39,7 @@ def replacedict(keys,dbport):
html += " "
html += ""
html += "" + scrobblesArtistLink(e["artist"],timekeys,amount=e["scrobbles"],associated=True) + " | "
- html += "" + scrobblesArtistLink(e["artist"],timekeys,pixels=e["scrobbles"]*100/maxbar,associated=True) + " | "
+ html += "" + scrobblesArtistLink(e["artist"],timekeys,percent=e["scrobbles"]*100/maxbar,associated=True) + " | "
html += ""
i += 1
html += ""
diff --git a/website/toptracks.py b/website/toptracks.py
index b8337bd..74262a4 100644
--- a/website/toptracks.py
+++ b/website/toptracks.py
@@ -10,6 +10,7 @@ def replacedict(keys,dbport):
timekeys = pickKeys(keys,"since","to","in")
limitkeys = pickKeys(keys,"artist")
+ # get chart data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
charts = db_data["list"][:50]
@@ -26,12 +27,14 @@ def replacedict(keys,dbport):
imgurl = info.get("image")
+ # get total amount of scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)
+ # build list
maxbar = charts[0]["scrobbles"]
i = 1
@@ -42,7 +45,7 @@ def replacedict(keys,dbport):
html += "" + artistLinks(e["track"]["artists"]) + " | "
html += "" + trackLink(e["track"]) + " | "
html += "" + scrobblesTrackLink(e["track"],timekeys,amount=e["scrobbles"]) + " | "
- html += "" + scrobblesTrackLink(e["track"],timekeys,pixels=e["scrobbles"]*100/maxbar) + " | "
+ html += "" + scrobblesTrackLink(e["track"],timekeys,percent=e["scrobbles"]*100/maxbar) + " | "
html += ""
i += 1
html += ""