1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00
maloja/website/topartists.py

45 lines
1.6 KiB
Python
Raw Normal View History

2018-12-17 18:33:26 +03:00
import urllib
import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, artistLink
2018-12-17 18:33:26 +03:00
#hand down the since and from arguments
extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/")
2018-12-17 18:33:26 +03:00
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + extrakeys)
db_data = json.loads(response.read())
charts = db_data["list"][:50]
topartist = charts[0]["artist"]
info = getArtistInfo(topartist)
imgurl = info.get("image")
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)
2018-12-22 02:31:27 +03:00
maxbar = charts[0]["scrobbles"]
2018-12-17 18:33:26 +03:00
2018-12-22 02:31:27 +03:00
i = 1
html = "<table class='list'>"
2018-12-17 18:33:26 +03:00
for e in charts:
2018-12-22 02:31:27 +03:00
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"])
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>"
2018-12-22 02:31:27 +03:00
html += "</tr>"
i += 1
2018-12-17 18:33:26 +03:00
html += "</table>"
return {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_SCROBBLES":str(scrobbles),"KEY_ARTISTLIST":html}