def instructions(keys): from utilities import getArtistImage from htmlgenerators import artistLink, artistLinks, link_address 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 += "<a title='Best Artist in " + str(y) + "' class='hidelink medal shiny gold' href='/charts_artists?in=" + str(y) + "'><span>" + str(y) + "</span></a>" if "silver" in data["medals"]: for y in data["medals"]["silver"]: html_medals += "<a title='Second Best Artist in " + str(y) + "' class='hidelink medal shiny silver' href='/charts_artists?in=" + str(y) + "'><span>" + str(y) + "</span></a>" if "bronze" in data["medals"]: for y in data["medals"]["bronze"]: html_medals += "<a title='Third Best Artist in " + str(y) + "' class='hidelink medal shiny bronze' href='/charts_artists?in=" + str(y) + "'><span>" + str(y) + "</span></a>" html_cert = "" for track in database.get_tracks(artist=artist): info = database.trackInfo(track) if info.get("certification") is not None: img = "/media/record_{cert}.png".format(cert=info["certification"]) trackname = track["title"].replace("'","'") tracklink = link_address(track) tooltip = "{title} has reached {cert} status".format(title=trackname,cert=info["certification"].capitalize()) html_cert += "<a href='{link}'><img class='certrecord_small' src='{img}' title='{tooltip}' /></a>".format(tooltip=tooltip,img=img,link=tracklink) html_topweeks = "" if data.get("topweeks") not in [0,None]: link = "/performance?artist=" + urllib.parse.quote(keys["artist"]) + "&trail=1&step=week" title = str(data["topweeks"]) + " weeks on #1" html_topweeks = "<a title='" + title + "' href='" + link + "'><img class='star' src='/media/star.png' />" + str(data["topweeks"]) + "</a>" credited = data.get("replace") includestr = " " if credited is not None: includestr = "Competing under " + artistLink(credited) + " (" + pos + ")" pos = "" else: credited = artist 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) # pulse and rankings html_pulse_days = module_pulse(**filterkeys,max_=7,since=today().next(-6),step="day",trail=1) html_pulse_weeks = module_pulse(**filterkeys,max_=12,since=thisweek().next(-11),step="week",trail=1) html_pulse_months = module_pulse(**filterkeys,max_=12,since=thismonth().next(-11),step="month",trail=1) html_pulse_years = module_pulse(**filterkeys,max_=10,since=thisyear().next(-9),step="year",trail=1) html_performance_days = module_performance(artist=credited,max_=7,since=today().next(-6),step="day",trail=1) html_performance_weeks = module_performance(artist=credited,max_=12,since=thisweek().next(-11),step="week",trail=1) html_performance_months = module_performance(artist=credited,max_=12,since=thismonth().next(-11),step="month",trail=1) html_performance_years = module_performance(artist=credited,max_=10,since=thisyear().next(-9),step="year",trail=1) replace = { # info "KEY_ARTISTNAME":keys["artist"], "KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]), "KEY_ENC_CREDITEDARTISTNAME":urllib.parse.quote(credited), "KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":"", "KEY_SCROBBLES":scrobbles, "KEY_POSITION":pos, "KEY_ASSOCIATED":includestr, "KEY_MEDALS":html_medals, "KEY_CERTS":html_cert, "KEY_TOPWEEKS":html_topweeks, # tracks "KEY_TRACKLIST":html_tracks, # pulse "KEY_PULSE_MONTHS":html_pulse_months, "KEY_PULSE_YEARS":html_pulse_years, "KEY_PULSE_DAYS":html_pulse_days, "KEY_PULSE_WEEKS":html_pulse_weeks, # performance "KEY_PERFORMANCE_MONTHS":html_performance_months, "KEY_PERFORMANCE_YEARS":html_performance_years, "KEY_PERFORMANCE_DAYS":html_performance_days, "KEY_PERFORMANCE_WEEKS":html_performance_weeks, # scrobbles "KEY_SCROBBLELIST":html_scrobbles, "KEY_SCROBBLELINK":compose_querystring(keys), } return (replace,pushresources)
def instructions(keys): # commands to execute on load for default ranges js_command = "showRange('topartists','" + get_settings( "DEFAULT_RANGE_CHARTS_ARTISTS") + "');" js_command += "showRange('toptracks','" + get_settings( "DEFAULT_RANGE_CHARTS_TRACKS") + "');" js_command += "showRange('pulse','" + get_settings( "DEFAULT_STEP_PULSE") + "');" clock() from malojatime import today, thisweek, thismonth, thisyear # artists topartists_total = module_artistcharts_tiles() topartists_year = module_artistcharts_tiles(timerange=thisyear()) topartists_month = module_artistcharts_tiles(timerange=thismonth()) topartists_week = module_artistcharts_tiles(timerange=thisweek()) clockp("Artists") # tracks toptracks_total = module_trackcharts_tiles() toptracks_year = module_trackcharts_tiles(timerange=thisyear()) toptracks_month = module_trackcharts_tiles(timerange=thismonth()) toptracks_week = module_trackcharts_tiles(timerange=thisweek()) clockp("Tracks") # scrobbles html_scrobbles, _, _ = module_scrobblelist(max_=15, shortTimeDesc=True, pictures=True, earlystop=True) clockp("Scrobbles") # stats amount_day = database.get_scrobbles_num(timerange=today()) scrobbles_today = "<a href='/scrobbles?in=today'>" + str( amount_day) + "</a>" amount_week = database.get_scrobbles_num(timerange=thisweek()) scrobbles_week = "<a href='/scrobbles?in=week'>" + str( amount_week) + "</a>" amount_month = database.get_scrobbles_num(timerange=thismonth()) scrobbles_month = "<a href='/scrobbles?in=month'>" + str( amount_month) + "</a>" amount_year = database.get_scrobbles_num(timerange=thisyear()) scrobbles_year = "<a href='/scrobbles?in=year'>" + str( amount_year) + "</a>" amount_total = database.get_scrobbles_num() scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>" clockp("Amounts") # pulse html_pulse_days = module_pulse(max_=7, since=today().next(-6), step="day", trail=1) html_pulse_weeks = module_pulse(max_=12, since=thisweek().next(-11), step="week", trail=1) html_pulse_months = module_pulse(max_=12, since=thismonth().next(-11), step="month", trail=1) html_pulse_years = module_pulse(max_=10, since=thisyear().next(-9), step="year", trail=1) #html_pulse_week = module_pulse(max_=7,since=weekstart,step="day",trail=1) #html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1) #html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1) clockp("Pulse") #pushresources = [{"file":img,"type":"image"} for img in artistimages + trackimages] #can't push scrobble images as we don't get them from the module function, need to think about that pushresources = [] replace = { "KEY_TOPARTISTS_TOTAL": topartists_total, "KEY_TOPARTISTS_YEAR": topartists_year, "KEY_TOPARTISTS_MONTH": topartists_month, "KEY_TOPARTISTS_WEEK": topartists_week, "KEY_TOPTRACKS_TOTAL": toptracks_total, "KEY_TOPTRACKS_YEAR": toptracks_year, "KEY_TOPTRACKS_MONTH": toptracks_month, "KEY_TOPTRACKS_WEEK": toptracks_week, "KEY_JS_INIT_RANGES": js_command, "KEY_SCROBBLE_NUM_TODAY": scrobbles_today, "KEY_SCROBBLE_NUM_WEEK": scrobbles_week, "KEY_SCROBBLE_NUM_MONTH": scrobbles_month, "KEY_SCROBBLE_NUM_YEAR": scrobbles_year, "KEY_SCROBBLE_NUM_TOTAL": scrobbles_total, "KEY_SCROBBLES": html_scrobbles, "KEY_PULSE_MONTHS": html_pulse_months, "KEY_PULSE_YEARS": html_pulse_years, "KEY_PULSE_DAYS": html_pulse_days, "KEY_PULSE_WEEKS": html_pulse_weeks, #"KEY_PULSE_YEAR":html_pulse_year,"KEY_PULSE_MONTH":html_pulse_month,"KEY_PULSE_WEEK":html_pulse_week } return (replace, pushresources)
def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesLink from urihandler import compose_querystring, uri_to_internal, internal_to_uri from htmlmodules import module_pulse, module_filterselection from malojatime import range_desc, delimit_desc filterkeys, timekeys, delimitkeys, _ = uri_to_internal(keys) #equivalent performance chart if we're not looking at the overall pulse if len(filterkeys) != 0: performancelink_keys = internal_to_uri({**filterkeys,**timekeys,**delimitkeys}) performancelink = "/performance?" + compose_querystring(performancelink_keys) performancelink = "<a href=\"" + performancelink + "\"><span>View Rankings</span></a>" else: performancelink = "" # describe the scope (and creating a key for the relevant artist or track) limitstring = "" #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"]) 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"): data = database.artistInfo(filterkeys["artist"]) moreartists = data["associated"] if moreartists != []: limitstring += " <span class='extra'>including " + artistLinks(moreartists) + "</span>" limitstring += " " + range_desc(timekeys["timerange"],prefix=True) delimitstring = delimit_desc(**delimitkeys) html_filterselector = module_filterselection(keys,delimit=True) # get image if filterkeys.get("track") is not None: imgurl = getTrackImage(filterkeys.get("track")["artists"],filterkeys.get("track")["title"]) elif filterkeys.get("artist") is not None: imgurl = getArtistImage(keys.get("artist")) else: imgurl = "" pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] html_pulse = module_pulse(**filterkeys,**timekeys,**delimitkeys) replace = { "KEY_RANKINGS_LINK":performancelink, "KEY_PULSE_TABLE":html_pulse, "KEY_IMAGEURL":imgurl, "KEY_LIMITS":limitstring, "KEY_PULSEDETAILS":delimitstring, "KEY_FILTERSELECTOR":html_filterselector } return (replace,pushresources)
def instructions(keys): from utilities import getArtistImage, getTrackImage from htmlgenerators import artistLinks from urihandler import compose_querystring, uri_to_internal from htmlmodules import module_scrobblelist, module_pulse, module_performance filterkeys, _, _, _ = uri_to_internal(keys, forceTrack=True) track = filterkeys.get("track") imgurl = getTrackImage(track["artists"], track["title"], fast=True) pushresources = [{ "file": imgurl, "type": "image" }] if imgurl.startswith("/") else [] data = database.trackInfo(track) scrobblesnum = str(data["scrobbles"]) pos = "#" + str(data["position"]) html_cert = "" if data["certification"] is not None: html_cert = "<img class='certrecord' src='/media/record_{cert}.png' title='This track has reached {certc} status' />".format( cert=data["certification"], certc=data["certification"].capitalize()) 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 += "<a title='Best Track in " + str( y ) + "' class='hidelink medal shiny gold' href='/charts_tracks?in=" + str( y) + "'><span>" + str(y) + "</span></a>" if "silver" in data["medals"]: for y in data["medals"]["silver"]: html_medals += "<a title='Second Best Track in " + str( y ) + "' class='hidelink medal shiny silver' href='/charts_tracks?in=" + str( y) + "'><span>" + str(y) + "</span></a>" if "bronze" in data["medals"]: for y in data["medals"]["bronze"]: html_medals += "<a title='Third Best Track in " + str( y ) + "' class='hidelink medal shiny bronze' href='/charts_tracks?in=" + str( y) + "'><span>" + str(y) + "</span></a>" html_topweeks = "" if data.get("topweeks") not in [0, None]: link = "/performance?" + compose_querystring( keys) + "&trail=1&step=week" title = str(data["topweeks"]) + " weeks on #1" html_topweeks = "<a title='" + title + "' href='" + link + "'><img class='star' src='/media/star.png' />" + str( data["topweeks"]) + "</a>" html_scrobbles, _, _ = module_scrobblelist( track=track, max_=10, earlystop=True) # we have the number already from the trackinfo html_pulse = module_pulse(track=track, step="year", stepn=1, trail=1) html_performance = module_performance(track=track, step="year", stepn=1, trail=1) # pulse and rankings html_pulse_days = module_pulse(track=track, max_=7, since=today().next(-6), step="day", trail=1) html_pulse_weeks = module_pulse(track=track, max_=12, since=thisweek().next(-11), step="week", trail=1) html_pulse_months = module_pulse(track=track, max_=12, since=thismonth().next(-11), step="month", trail=1) html_pulse_years = module_pulse(track=track, max_=10, since=thisyear().next(-9), step="year", trail=1) html_performance_days = module_performance(track=track, max_=7, since=today().next(-6), step="day", trail=1) html_performance_weeks = module_performance(track=track, max_=12, since=thisweek().next(-11), step="week", trail=1) html_performance_months = module_performance(track=track, max_=12, since=thismonth().next(-11), step="month", trail=1) html_performance_years = module_performance(track=track, max_=10, since=thisyear().next(-9), step="year", trail=1) replace = { "KEY_TRACKTITLE": track.get("title"), "KEY_ARTISTS": artistLinks(track.get("artists")), "KEY_SCROBBLES": scrobblesnum, "KEY_POSITION": pos, "KEY_IMAGEURL": imgurl, "KEY_SCROBBLELINK": compose_querystring(keys), "KEY_MEDALS": html_medals, "KEY_CERTS": html_cert, "KEY_TOPWEEKS": html_topweeks, "KEY_SCROBBLELIST": html_scrobbles, # pulse "KEY_PULSE_MONTHS": html_pulse_months, "KEY_PULSE_YEARS": html_pulse_years, "KEY_PULSE_DAYS": html_pulse_days, "KEY_PULSE_WEEKS": html_pulse_weeks, # performance "KEY_PERFORMANCE_MONTHS": html_performance_months, "KEY_PERFORMANCE_YEARS": html_performance_years, "KEY_PERFORMANCE_DAYS": html_performance_days, "KEY_PERFORMANCE_WEEKS": html_performance_weeks, } return (replace, pushresources)
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 += "<a title='Best Artist in " + str(y) + "' class='hidelink medal shiny gold' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>" if "silver" in data["medals"]: for y in data["medals"]["silver"]: html_medals += "<a title='Second Best Artist in " + str(y) + "' class='hidelink medal shiny silver' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>" if "bronze" in data["medals"]: for y in data["medals"]["bronze"]: html_medals += "<a title='Third Best Artist in " + str(y) + "' class='hidelink medal shiny bronze' href='/charts_artists?max=50&in=" + str(y) + "'><span>" + str(y) + "</span></a>" credited = data.get("replace") includestr = " " if credited is not None: includestr = "Competing under " + artistLink(credited) + " (" + pos + ")" pos = "" else: credited = artist 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) # pulse and rankings html_pulse_days = module_pulse(**filterkeys,max_=7,since=today().next(-6),step="day",trail=1) html_pulse_weeks = module_pulse(**filterkeys,max_=12,since=thisweek().next(-11),step="week",trail=1) html_pulse_months = module_pulse(**filterkeys,max_=12,since=thismonth().next(-11),step="month",trail=1) html_pulse_years = module_pulse(**filterkeys,max_=10,since=thisyear().next(-9),step="year",trail=1) html_performance_days = module_performance(artist=credited,max_=7,since=today().next(-6),step="day",trail=1) html_performance_weeks = module_performance(artist=credited,max_=12,since=thisweek().next(-11),step="week",trail=1) html_performance_months = module_performance(artist=credited,max_=12,since=thismonth().next(-11),step="month",trail=1) html_performance_years = module_performance(artist=credited,max_=10,since=thisyear().next(-9),step="year",trail=1) replace = { # info "KEY_ARTISTNAME":keys["artist"], "KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]), "KEY_ENC_CREDITEDARTISTNAME":urllib.parse.quote(credited), "KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":"", "KEY_SCROBBLES":scrobbles, "KEY_POSITION":pos, "KEY_ASSOCIATED":includestr, "KEY_MEDALS":html_medals, # tracks "KEY_TRACKLIST":html_tracks, # pulse "KEY_PULSE_MONTHS":html_pulse_months, "KEY_PULSE_YEARS":html_pulse_years, "KEY_PULSE_DAYS":html_pulse_days, "KEY_PULSE_WEEKS":html_pulse_weeks, # performance "KEY_PERFORMANCE_MONTHS":html_performance_months, "KEY_PERFORMANCE_YEARS":html_performance_years, "KEY_PERFORMANCE_DAYS":html_performance_days, "KEY_PERFORMANCE_WEEKS":html_performance_weeks, # scrobbles "KEY_SCROBBLELIST":html_scrobbles, "KEY_SCROBBLELINK":compose_querystring(keys), } return (replace,pushresources)