mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Modularizing HTML generation, Part I
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<span>KEY_ASSOCIATED</span>
|
||||
<p class="stats"><a href="/scrobbles?artist=KEY_ENC_ARTISTNAME">KEY_SCROBBLES Scrobbles</a></p>
|
||||
|
||||
<p>KEY_DESCRIPTION</p>
|
||||
<p class="desc">KEY_DESCRIPTION</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@@ -39,6 +39,15 @@ table.top_info td.text h1 {
|
||||
display:inline;
|
||||
padding-right:5px;
|
||||
}
|
||||
|
||||
p.desc a {
|
||||
padding-left:20px;
|
||||
background-repeat:no-repeat;
|
||||
background-size:contain;
|
||||
background-position:left;
|
||||
background-image:url("https://www.last.fm/static/images/lastfm_avatar_twitter.66cd2c48ce03.png");
|
||||
}
|
||||
|
||||
/*
|
||||
table.top_info td.text .stats {
|
||||
color:grey;
|
||||
|
||||
@@ -3,16 +3,15 @@ import json
|
||||
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo, getTimeDesc, artistLink, keysToUrl
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import getTimeDesc, artistLink, keysToUrl, pickKeys
|
||||
|
||||
|
||||
#hand down the since and from arguments
|
||||
#extrakeys = urllib.parse.urlencode(keys,doseq=True)
|
||||
extrakeys = keysToUrl(keys)
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys,"artist","title")
|
||||
|
||||
limitstring = ""
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys,timekeys))
|
||||
db_data = json.loads(response.read())
|
||||
scrobbles = db_data["list"]
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@ import json
|
||||
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo, artistLink
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import artistLink, keysToUrl, pickKeys
|
||||
|
||||
#hand down the since and from arguments
|
||||
extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/")
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys)
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + extrakeys)
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
|
||||
db_data = json.loads(response.read())
|
||||
charts = db_data["list"][:50]
|
||||
topartist = charts[0]["artist"]
|
||||
@@ -17,7 +18,7 @@ def replacedict(keys,dbport):
|
||||
imgurl = info.get("image")
|
||||
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
|
||||
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)
|
||||
@@ -34,8 +35,8 @@ def replacedict(keys,dbport):
|
||||
html += 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&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td>"
|
||||
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&associated&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a></td>"
|
||||
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 += "</tr>"
|
||||
i += 1
|
||||
html += "</table>"
|
||||
|
||||
@@ -3,18 +3,13 @@ import json
|
||||
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
from utilities import getArtistInfo, artistLink, keysToUrl
|
||||
from utilities import getArtistInfo
|
||||
from htmlgenerators import artistLink, keysToUrl, pickKeys
|
||||
|
||||
# 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)
|
||||
timekeys = pickKeys(keys,"since","to","in")
|
||||
limitkeys = pickKeys(keys,"artist")
|
||||
|
||||
#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)
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks?" + keysToUrl(timekeys,limitkeys))
|
||||
db_data = json.loads(response.read())
|
||||
charts = db_data["list"][:50]
|
||||
limitstring = ""
|
||||
@@ -30,7 +25,7 @@ def replacedict(keys,dbport):
|
||||
imgurl = info.get("image")
|
||||
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
|
||||
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)
|
||||
@@ -45,8 +40,8 @@ def replacedict(keys,dbport):
|
||||
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"]) + "&" + extrakeys + "'>" + 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"]) + "&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a>"
|
||||
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 += "</tr>"
|
||||
i += 1
|
||||
|
||||
Reference in New Issue
Block a user