2018-12-17 18:33:26 +03:00
|
|
|
import urllib
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
def instructions(keys,dbport):
|
2018-12-26 19:42:55 +03:00
|
|
|
from utilities import getArtistInfo
|
2019-02-20 20:22:45 +03:00
|
|
|
from htmlgenerators import KeySplit
|
|
|
|
from htmlmodules import module_artistcharts
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
# clean(keys)
|
|
|
|
# timekeys = pickKeys(keys,"since","to","in")
|
|
|
|
# limitkeys = pickKeys(keys)
|
|
|
|
|
|
|
|
_, timekeys, _, amountkeys = KeySplit(keys)
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
# get chart data
|
2019-02-20 20:22:45 +03:00
|
|
|
# response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
|
|
|
|
# db_data = json.loads(response.read())
|
|
|
|
# charts = db_data["list"][:50]
|
|
|
|
# topartist = charts[0]["artist"]
|
|
|
|
|
|
|
|
# info = getArtistInfo(topartist)
|
|
|
|
# imgurl = info.get("image")
|
2018-12-17 18:33:26 +03:00
|
|
|
|
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
# get total amount of scrobbles
|
2019-02-20 20:22:45 +03:00
|
|
|
#response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
|
|
|
|
#db_data = json.loads(response.read())
|
|
|
|
#scrobblelist = db_data["list"]
|
|
|
|
#scrobbles = len(scrobblelist)
|
|
|
|
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
html_charts, rep = module_artistcharts(**amountkeys,**timekeys)
|
|
|
|
|
|
|
|
if rep is not None:
|
|
|
|
imgurl = getArtistInfo(rep).get("image")
|
|
|
|
else:
|
|
|
|
imgurl = ""
|
|
|
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2018-12-27 05:09:29 +03:00
|
|
|
# build list
|
2019-02-20 20:22:45 +03:00
|
|
|
# maxbar = charts[0]["scrobbles"]
|
|
|
|
#
|
|
|
|
# i = 1
|
|
|
|
# html = "<table class='list'>"
|
|
|
|
# for e in charts:
|
|
|
|
# html += "<tr>"
|
|
|
|
# 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>"
|
|
|
|
# html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],timekeys,amount=e["scrobbles"],associated=True) + "</td>"
|
|
|
|
# html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],timekeys,percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
|
|
|
|
# html += "</tr>"
|
|
|
|
# i += 1
|
|
|
|
# html += "</table>"
|
|
|
|
|
|
|
|
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_ARTISTLIST":html_charts}
|
2018-12-17 18:33:26 +03:00
|
|
|
|
2019-02-17 16:25:40 +03:00
|
|
|
return (replace,pushresources)
|