import urllib
import database
def instructions(keys):
from utilities import getArtistImage
from htmlgenerators import artistLink, artistLinks
from urihandler import compose_querystring, uri_to_internal
from htmlmodules import module_pulse, module_performance, module_trackcharts, module_scrobblelist
filterkeys, _, _, _ = uri_to_internal(keys,forceArtist=True)
artist = filterkeys.get("artist")
imgurl = getArtistImage(filterkeys["artist"],fast=True)
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
data = database.artistInfo(filterkeys["artist"])
scrobbles = str(data["scrobbles"])
pos = "#" + str(data["position"])
html_medals = ""
if "medals" in data and data["medals"] is not None:
if "gold" in data["medals"]:
for y in data["medals"]["gold"]:
html_medals += "" + str(y) + ""
if "silver" in data["medals"]:
for y in data["medals"]["silver"]:
html_medals += "" + str(y) + ""
if "bronze" in data["medals"]:
for y in data["medals"]["bronze"]:
html_medals += "" + str(y) + ""
credited = data.get("replace")
includestr = " "
if credited is not None:
includestr = "Competing under " + artistLink(credited) + " (" + pos + ")"
pos = ""
included = data.get("associated")
if included is not None and included != []:
includestr = "associated: "
includestr += artistLinks(included)
html_tracks, _ = module_trackcharts(**filterkeys,max_=15)
html_scrobbles, _, _ = module_scrobblelist(artist=artist,max_=10,earlystop=True)
html_pulse = module_pulse(**filterkeys,step="year",stepn=1,trail=1)
html_performance = module_performance(**filterkeys,step="year",stepn=1,trail=1)
replace = {
"KEY_ARTISTNAME":keys["artist"],
"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),
"KEY_IMAGEURL":imgurl,
"KEY_DESCRIPTION":"",
"KEY_MEDALS":html_medals,
"KEY_TRACKLIST":html_tracks,
"KEY_PULSE":html_pulse,
"KEY_PERFORMANCE":html_performance,
"KEY_SCROBBLES":scrobbles,
"KEY_SCROBBLELIST":html_scrobbles,
"KEY_SCROBBLELINK":compose_querystring(keys),
"KEY_POSITION":pos,
"KEY_ASSOCIATED":includestr
}
return (replace,pushresources)