mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Modularizing HTML generation, Part II
This commit is contained in:
@@ -3,7 +3,8 @@ import json
|
||||
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo, artistLink
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import artistLink
|
||||
|
||||
|
||||
info = getArtistInfo(keys["artist"])
|
||||
|
||||
@@ -4,13 +4,13 @@ import json
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import getTimeDesc, artistLink, keysToUrl, pickKeys
|
||||
from htmlgenerators import getTimeDesc, artistLink, artistLinks, trackLink, keysToUrl, pickKeys, clean
|
||||
|
||||
clean(keys)
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys,"artist","title")
|
||||
limitkeys = pickKeys(keys,"artist","title","associated")
|
||||
|
||||
limitstring = ""
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys,timekeys))
|
||||
db_data = json.loads(response.read())
|
||||
scrobbles = db_data["list"]
|
||||
@@ -38,16 +38,10 @@ def replacedict(keys,dbport):
|
||||
|
||||
html = "<table class='list'>"
|
||||
for s in scrobbles:
|
||||
html += "<tr><td class='time'>"
|
||||
timestring = getTimeDesc(s["time"])
|
||||
html += timestring
|
||||
html += "</td><td class='artists'>"
|
||||
html += ", ".join([artistLink(a) for a in s["artists"]])
|
||||
#artisthtml = ""
|
||||
#for a in s["artists"]:
|
||||
# artisthtml += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
|
||||
#html += artisthtml[:-2]
|
||||
html += "</td><td class='title'>" + s["title"] + "</td></tr>"
|
||||
html += "<tr>"
|
||||
html += "<td class='time'>" + getTimeDesc(s["time"]) + "</td>"
|
||||
html += "<td class='artists'>" + artistLinks(s["artists"]) + "</td>"
|
||||
html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td></tr>"
|
||||
html += "</table>"
|
||||
|
||||
return {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(len(scrobbles)),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
|
||||
|
||||
@@ -4,8 +4,9 @@ import json
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import artistLink, keysToUrl, pickKeys
|
||||
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, keysToUrl, pickKeys, clean
|
||||
|
||||
clean(keys)
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys)
|
||||
|
||||
@@ -30,13 +31,13 @@ def replacedict(keys,dbport):
|
||||
html = "<table class='list'>"
|
||||
for e in charts:
|
||||
html += "<tr>"
|
||||
html += "<td class='rank'>#" + str(i) + "</td><td class='artist'>"
|
||||
#html += "<a href=/artist?artist=" + urllib.parse.quote(e["artist"]) + ">" + e["artist"] + "</a>"
|
||||
html += artistLink(e["artist"])
|
||||
html += "<td class='rank'>#" + str(i) + "</td>"
|
||||
html += "<td class='artist'>" + artistLink(e["artist"])
|
||||
if (e["counting"] != []):
|
||||
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
|
||||
html += "</td><td class='amount'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&associated&" + keysToUrl(timekeys) + "'>" + str(e["scrobbles"]) + "</a></td>"
|
||||
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&associated&" + keysToUrl(timekeys) + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a></td>"
|
||||
html += "</td>"
|
||||
html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],timekeys,amount=e["scrobbles"],associated=True) + "</td>"
|
||||
html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],timekeys,pixels=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
|
||||
html += "</tr>"
|
||||
i += 1
|
||||
html += "</table>"
|
||||
|
||||
@@ -4,8 +4,9 @@ import json
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import artistLink, keysToUrl, pickKeys
|
||||
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesTrackLink, keysToUrl, pickKeys, clean
|
||||
|
||||
clean(keys)
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys,"artist")
|
||||
|
||||
@@ -37,12 +38,11 @@ def replacedict(keys,dbport):
|
||||
html = "<table class='list'>"
|
||||
for e in charts:
|
||||
html += "<tr>"
|
||||
html += "<td class='rank'>#" + str(i) + "</td><td class='artists'>"
|
||||
html += ", ".join([artistLink(a) for a in e["track"]["artists"]])
|
||||
html += "</td><td class='title'>" + e["track"]["title"]
|
||||
html += "</td><td class='amount'><a href='/scrobbles?" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) + "&title=" + urllib.parse.quote(e["track"]["title"]) + "&" + keysToUrl(timekeys) + "'>" + str(e["scrobbles"]) + "</a></td>"
|
||||
html += "<td class='bar'><a href='/scrobbles?" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) + "&title=" + urllib.parse.quote(e["track"]["title"]) + "&" + keysToUrl(timekeys) + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a>"
|
||||
html += "</td>"
|
||||
html += "<td class='rank'>#" + str(i) + "</td>"
|
||||
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
|
||||
html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
|
||||
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],timekeys,amount=e["scrobbles"]) + "</td>"
|
||||
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],timekeys,pixels=e["scrobbles"]*100/maxbar) + "</td>"
|
||||
html += "</tr>"
|
||||
i += 1
|
||||
html += "</table>"
|
||||
|
||||
Reference in New Issue
Block a user