2019-02-18 17:52:08 +03:00
|
|
|
import urllib
|
2019-02-21 11:43:35 +03:00
|
|
|
import database
|
2019-02-18 17:52:08 +03:00
|
|
|
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-02-21 11:43:35 +03:00
|
|
|
def instructions(keys):
|
2019-03-12 13:39:36 +03:00
|
|
|
from utilities import getArtistImage, getTrackImage
|
2019-04-08 14:04:31 +03:00
|
|
|
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink
|
2019-04-23 18:47:49 +03:00
|
|
|
from urihandler import compose_querystring, uri_to_internal, internal_to_uri
|
2019-04-01 19:43:08 +03:00
|
|
|
from htmlmodules import module_pulse, module_filterselection
|
2019-03-03 00:55:22 +03:00
|
|
|
from malojatime import range_desc, delimit_desc
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-06-17 16:07:23 +03:00
|
|
|
filterkeys, timekeys, delimitkeys, paginatekeys = uri_to_internal(keys)
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-04-23 18:47:49 +03:00
|
|
|
#equivalent performance chart if we're not looking at the overall pulse
|
|
|
|
if len(filterkeys) != 0:
|
2019-06-17 16:07:23 +03:00
|
|
|
performancelink_keys = internal_to_uri({**filterkeys,**timekeys,**delimitkeys,**paginatekeys})
|
2019-04-23 18:47:49 +03:00
|
|
|
performancelink = "/performance?" + compose_querystring(performancelink_keys)
|
|
|
|
|
|
|
|
performancelink = "<a href=\"" + performancelink + "\"><span>View Rankings</span></a>"
|
|
|
|
else:
|
|
|
|
performancelink = ""
|
|
|
|
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-02-18 17:52:08 +03:00
|
|
|
# describe the scope (and creating a key for the relevant artist or track)
|
|
|
|
limitstring = ""
|
2019-02-20 20:22:45 +03:00
|
|
|
#limitkey = {}
|
|
|
|
if filterkeys.get("track") is not None:
|
|
|
|
#limitkey["track"] = {"artists":keys.getall("artist"),"title":keys.get("title")}
|
|
|
|
limitstring += "of " + trackLink(filterkeys["track"]) + " "
|
|
|
|
limitstring += "by " + artistLinks(filterkeys["track"]["artists"])
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-02-20 20:22:45 +03:00
|
|
|
elif filterkeys.get("artist") is not None:
|
|
|
|
#limitkey["artist"], limitkey["associated"] = keys.get("artist"), (keys.get("associated")!=None)
|
|
|
|
limitstring += "of " + artistLink(filterkeys.get("artist"))
|
|
|
|
if filterkeys.get("associated"):
|
2019-02-21 11:43:35 +03:00
|
|
|
data = database.artistInfo(filterkeys["artist"])
|
|
|
|
moreartists = data["associated"]
|
2019-02-18 17:52:08 +03:00
|
|
|
if moreartists != []:
|
|
|
|
limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-04-10 18:56:40 +03:00
|
|
|
limitstring += " " + range_desc(timekeys["timerange"],prefix=True)
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-03-03 00:55:22 +03:00
|
|
|
delimitstring = delimit_desc(**delimitkeys)
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-04-01 19:43:08 +03:00
|
|
|
html_filterselector = module_filterselection(keys,delimit=True)
|
|
|
|
|
2019-03-29 21:44:42 +03:00
|
|
|
|
|
|
|
# get image
|
2019-02-20 20:22:45 +03:00
|
|
|
if filterkeys.get("track") is not None:
|
2019-03-12 13:39:36 +03:00
|
|
|
imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"])
|
2019-02-20 20:22:45 +03:00
|
|
|
elif filterkeys.get("artist") is not None:
|
2019-03-12 13:39:36 +03:00
|
|
|
imgurl = getArtistImage(keys.get("artist"))
|
2019-02-18 17:52:08 +03:00
|
|
|
else:
|
|
|
|
imgurl = ""
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-02-18 17:52:08 +03:00
|
|
|
pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else []
|
|
|
|
|
2019-03-29 21:44:42 +03:00
|
|
|
|
|
|
|
|
2019-06-17 16:07:23 +03:00
|
|
|
html_pulse = module_pulse(**filterkeys,**timekeys,**delimitkeys,**paginatekeys)
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-04-23 18:47:49 +03:00
|
|
|
replace = {
|
|
|
|
"KEY_RANKINGS_LINK":performancelink,
|
|
|
|
"KEY_PULSE_TABLE":html_pulse,
|
|
|
|
"KEY_IMAGEURL":imgurl,
|
|
|
|
"KEY_LIMITS":limitstring,
|
|
|
|
"KEY_PULSEDETAILS":delimitstring,
|
|
|
|
"KEY_FILTERSELECTOR":html_filterselector
|
|
|
|
}
|
2019-03-29 21:44:42 +03:00
|
|
|
|
2019-02-18 17:52:08 +03:00
|
|
|
return (replace,pushresources)
|