Example #1
0
def module_paginate(page,pages,perpage,**keys):

	unchangedkeys = internal_to_uri({**keys,"perpage":perpage})

	html = "<div class='paginate'>"

	if page > 1:
		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":0})) + "'><span class='stat_selector'>" + "1" + "</span></a>"
		html += " | "

	if page > 2:
		html += " ... | "

	if page > 0:
		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":page-1})) + "'><span class='stat_selector'>" + str(page) + "</span></a>"
		html += " « "

	html += "<span style='opacity:0.5;' class='stat_selector'>" + str(page+1) + "</span>"

	if page < pages-1:
		html += " » "
		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":page+1})) + "'><span class='stat_selector'>" + str(page+2) + "</span></a>"

	if page < pages-3:
		html += " | ... "

	if page < pages-2:
		html += " | "
		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"page":pages-1})) + "'><span class='stat_selector'>" + str(pages) + "</span></a>"


	html += "</div>"

	return html
Example #2
0
def rankArtistLink(artist,timekeys,rank=None,percent=None,medal=None):
	cl = ""
	if medal == 1: cl = "class='gold'"
	if medal == 2: cl = "class='silver'"
	if medal == 3: cl = "class='bronze'"
	inner = str(rank) if rank is not None else "<div " + cl + " style='width:" + str(percent) + "%;'></div>"
	return "<a href='/charts_artists?" + compose_querystring(timekeys) + "'>" + inner + "</a>"
Example #3
0
def search():
    keys = FormsDict.decode(request.query)
    query = keys.get("query")
    max_ = keys.get("max")
    if max_ is not None: max_ = int(max_)
    query = query.lower()

    artists = db_search(query, type="ARTIST")
    tracks = db_search(query, type="TRACK")

    # if the string begins with the query it's a better match, if a word in it begins with it, still good
    # also, shorter is better (because longer titles would be easier to further specify)
    artists.sort(key=lambda x: ((0 if x.lower().startswith(query) else 1
                                 if " " + query in x.lower() else 2), len(x)))
    tracks.sort(key=lambda x: (
        (0 if x["title"].lower().startswith(query) else 1
         if " " + query in x["title"].lower() else 2), len(x["title"])))

    # add links
    artists_result = []
    for a in artists:
        result = {"name": a}
        result["link"] = "/artist?" + compose_querystring(
            internal_to_uri({"artist": a}))
        result["image"] = "/image?" + compose_querystring(
            internal_to_uri({"artist": a}))
        artists_result.append(result)

    tracks_result = []
    for t in tracks:
        result = t
        result["link"] = "/track?" + compose_querystring(
            internal_to_uri({"track": t}))
        result["image"] = "/image?" + compose_querystring(
            internal_to_uri({"track": t}))
        tracks_result.append(result)

    return {"artists": artists_result[:max_], "tracks": tracks_result[:max_]}
Example #4
0
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("'","&#39;")
			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)
Example #5
0
def module_filterselection(keys,time=True,delimit=False):

	filterkeys, timekeys, delimitkeys, extrakeys = uri_to_internal(keys)

	# drop keys that are not relevant so they don't clutter the URI
	if not time: timekeys = {}
	if not delimit: delimitkeys = {}

	html = ""

	if time:
		# all other keys that will not be changed by clicking another filter
		#keystr = "?" + compose_querystring(keys,exclude=["since","to","in"])
		unchangedkeys = internal_to_uri({**filterkeys,**delimitkeys,**extrakeys})


		# wonky selector for precise date range

#		fromdate = start_of_scrobbling()
#		todate = end_of_scrobbling()
#		if keys.get("since") is not None: fromdate = keys.get("since")
#		if keys.get("to") is not None: todate = keys.get("to")
#		if keys.get("in") is not None: fromdate, todate = keys.get("in"), keys.get("in")
#		fromdate = time_fix(fromdate)
#		todate = time_fix(todate)
#		fromdate, todate = time_pad(fromdate,todate,full=True)
#		fromdate = [str(e) if e>9 else "0" + str(e) for e in fromdate]
#		todate = [str(e) if e>9 else "0" + str(e) for e in todate]
#
#		html += "<div>"
#		html += "from <input id='dateselect_from' onchange='datechange()' type='date' value='" + "-".join(fromdate) + "'/> "
#		html += "to <input id='dateselect_to' onchange='datechange()' type='date' value='" + "-".join(todate) + "'/>"
#		html += "</div>"

		from malojatime import today, thisweek, thismonth, thisyear

		### temp!!! this will not allow weekly rank changes
	#	weekday = ((now.isoweekday()) % 7)
	#	weekbegin = now - datetime.timedelta(days=weekday)
	#	weekend = weekbegin + datetime.timedelta(days=6)
	#	weekbegin = [weekbegin.year,weekbegin.month,weekbegin.day]
	#	weekend = [weekend.year,weekend.month,weekend.day]
	#	weekbeginstr = "/".join((str(num) for num in weekbegin))
	#	weekendstr = "/".join((str(num) for num in weekend))



		# relative to current range

		html += "<div>"
	#	if timekeys.get("timerange").next(-1) is not None:
	#		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":timekeys.get("timerange").next(-1)})) + "'><span class='stat_selector'>«</span></a>"
	#	if timekeys.get("timerange").next(-1) is not None or timekeys.get("timerange").next(1) is not None:
	#		html += " " + timekeys.get("timerange").desc() + " "
	#	if timekeys.get("timerange").next(1) is not None:
	#		html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":timekeys.get("timerange").next(1)})) + "'><span class='stat_selector'>»</span></a>"

		if timekeys.get("timerange").next(-1) is not None:
			prevrange = timekeys.get("timerange").next(-1)
			html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":prevrange})) + "'><span class='stat_selector'>" + prevrange.desc() + "</span></a>"
			html += " « "
		if timekeys.get("timerange").next(-1) is not None or timekeys.get("timerange").next(1) is not None:
			html += "<span class='stat_selector' style='opacity:0.5;'>" + timekeys.get("timerange").desc() + "</span>"
		if timekeys.get("timerange").next(1) is not None:
			html += " » "
			nextrange = timekeys.get("timerange").next(1)
			html += "<a href='?" + compose_querystring(unchangedkeys,internal_to_uri({"timerange":nextrange})) + "'><span class='stat_selector'>" + nextrange.desc() + "</span></a>"

		html += "</div>"


		# predefined ranges

		html += "<div>"
		if timekeys.get("timerange") == today():
			html += "<span class='stat_selector' style='opacity:0.5;'>Today</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"today"}) + "'><span class='stat_selector'>Today</span></a>"
		html += " | "

		if timekeys.get("timerange") == thisweek():
			html += "<span class='stat_selector' style='opacity:0.5;'>This Week</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"week"}) + "'><span class='stat_selector'>This Week</span></a>"
		html += " | "

		if timekeys.get("timerange") == thismonth():
			html += "<span class='stat_selector' style='opacity:0.5;'>This Month</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"month"}) + "'><span class='stat_selector'>This Month</span></a>"
		html += " | "

		if timekeys.get("timerange") == thisyear():
			html += "<span class='stat_selector' style='opacity:0.5;'>This Year</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,{"in":"year"}) + "'><span class='stat_selector'>This Year</span></a>"
		html += " | "

		if timekeys.get("timerange") is None or timekeys.get("timerange").unlimited():
			html += "<span class='stat_selector' style='opacity:0.5;'>All Time</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys) + "'><span class='stat_selector'>All Time</span></a>"

		html += "</div>"

	if delimit:

		#keystr = "?" + compose_querystring(keys,exclude=["step","stepn"])
		unchangedkeys = internal_to_uri({**filterkeys,**timekeys,**extrakeys})

		# only for this element (delimit selector consists of more than one)
		unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k not in ["step","stepn"]})

		html += "<div>"
		if delimitkeys.get("step") == "day" and delimitkeys.get("stepn") == 1:
			html += "<span class='stat_selector' style='opacity:0.5;'>Daily</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"day"}) + "'><span class='stat_selector'>Daily</span></a>"
		html += " | "

		if delimitkeys.get("step") == "week" and delimitkeys.get("stepn") == 1:
			html += "<span class='stat_selector' style='opacity:0.5;'>Weekly</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"week"}) + "'><span class='stat_selector'>Weekly</span></a>"
		html += " | "

		if delimitkeys.get("step") == "month" and delimitkeys.get("stepn") == 1:
			html += "<span class='stat_selector' style='opacity:0.5;'>Monthly</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"month"}) + "'><span class='stat_selector'>Monthly</span></a>"
		html += " | "

		if delimitkeys.get("step") == "year" and delimitkeys.get("stepn") == 1:
			html += "<span class='stat_selector' style='opacity:0.5;'>Yearly</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"step":"year"}) + "'><span class='stat_selector'>Yearly</span></a>"

		html += "</div>"



		unchangedkeys_sub = internal_to_uri({k:delimitkeys[k] for k in delimitkeys if k != "trail"})

		html += "<div>"
		if delimitkeys.get("trail") == 1:
			html += "<span class='stat_selector' style='opacity:0.5;'>Standard</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"1"}) + "'><span class='stat_selector'>Standard</span></a>"
		html += " | "

		if delimitkeys.get("trail") == 2:
			html += "<span class='stat_selector' style='opacity:0.5;'>Trailing</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"2"}) + "'><span class='stat_selector'>Trailing</span></a>"
		html += " | "

		if delimitkeys.get("trail") == 3:
			html += "<span class='stat_selector' style='opacity:0.5;'>Long Trailing</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"trail":"3"}) + "'><span class='stat_selector'>Long Trailing</span></a>"
		html += " | "

		if delimitkeys.get("trail") == math.inf:
			html += "<span class='stat_selector' style='opacity:0.5;'>Cumulative</span>"
		else:
			html += "<a href='?" + compose_querystring(unchangedkeys,unchangedkeys_sub,{"cumulative":"yes"}) + "'><span class='stat_selector'>Cumulative</span></a>"

		html += "</div>"

	return html
Example #6
0
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_performance, module_filterselection
    from malojatime import range_desc, delimit_desc

    filterkeys, timekeys, delimitkeys, paginatekeys = uri_to_internal(keys)

    #equivalent pulse chart
    pulselink_keys = internal_to_uri({
        **filterkeys,
        **timekeys,
        **delimitkeys,
        **paginatekeys
    })
    pulselink = "/pulse?" + compose_querystring(pulselink_keys)

    pulselink = "<a href=\"" + pulselink + "\"><span>View Pulse</span></a>"

    # 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"))
        # associated are counted by default
        data = database.artistInfo(filterkeys["artist"])
        moreartists = data["associated"]
        if moreartists != []:
            limitstring += " <span class='extra'>including " + artistLinks(
                moreartists) + "</span>"

    limitstring += " " + timekeys["timerange"].desc(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_performance = module_performance(**filterkeys, **timekeys,
                                          **delimitkeys, **paginatekeys)

    replace = {
        "KEY_PULSE_LINK": pulselink,
        "KEY_PERFORMANCE_TABLE": html_performance,
        "KEY_IMAGEURL": imgurl,
        "KEY_LIMITS": limitstring,
        "KEY_PULSEDETAILS": delimitstring,
        "KEY_FILTERSELECTOR": html_filterselector
    }

    return (replace, pushresources)
Example #7
0
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)
Example #8
0
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)
Example #9
0
def scrobblesLink(timekeys,amount=None,percent=None,artist=None,track=None,associated=False):
	if track is not None: return scrobblesTrackLink(track,timekeys,amount,percent)
	if artist is not None: return scrobblesArtistLink(artist,timekeys,amount,percent,associated)
	inner = str(amount) if amount is not None else "<div style='width:" + str(percent) + "%;'></div>"
	return "<a href='/scrobbles?" + compose_querystring(timekeys) + "'>" + inner + "</a>"
Example #10
0
def scrobblesArtistLink(artist,timekeys,amount=None,percent=None,associated=False):
	inner = str(amount) if amount is not None else "<div style='width:" + str(percent) + "%;'></div>"
	askey = "&associated" if associated else ""
	return "<a href='/scrobbles?" + uri_query(artist) + "&" + compose_querystring(timekeys) + askey + "'>" + inner + "</a>"
Example #11
0
def scrobblesTrackLink(track,timekeys,amount=None,percent=None):
	artists,title = track["artists"],track["title"]
	inner = str(amount) if amount is not None else "<div style='width:" + str(percent) + "%;'></div>"
	return "<a href='/scrobbles?" + uri_query(track) + "&" + compose_querystring(timekeys) + "'>" + inner + "</a>"
Example #12
0
def module_filterselection(keys,time=True,delimit=False):

	from malojatime import today, thisweek, thismonth, thisyear, alltime

	filterkeys, timekeys, delimitkeys, extrakeys = uri_to_internal(keys)
	# drop keys that are not relevant so they don't clutter the URI
	if not time: timekeys = {}
	if not delimit: delimitkeys = {}
	if "page" in extrakeys: del extrakeys["page"]
	internalkeys = {**filterkeys,**timekeys,**delimitkeys,**extrakeys}

	html = ""


	if time:

		# wonky selector for precise date range

#		fromdate = start_of_scrobbling()
#		todate = end_of_scrobbling()
#		if keys.get("since") is not None: fromdate = keys.get("since")
#		if keys.get("to") is not None: todate = keys.get("to")
#		if keys.get("in") is not None: fromdate, todate = keys.get("in"), keys.get("in")
#		fromdate = time_fix(fromdate)
#		todate = time_fix(todate)
#		fromdate, todate = time_pad(fromdate,todate,full=True)
#		fromdate = [str(e) if e>9 else "0" + str(e) for e in fromdate]
#		todate = [str(e) if e>9 else "0" + str(e) for e in todate]
#
#		html += "<div>"
#		html += "from <input id='dateselect_from' onchange='datechange()' type='date' value='" + "-".join(fromdate) + "'/> "
#		html += "to <input id='dateselect_to' onchange='datechange()' type='date' value='" + "-".join(todate) + "'/>"
#		html += "</div>"

		# relative to current range
		html += "<div>"

		thisrange = timekeys.get("timerange")
		prevrange = thisrange.next(-1)
		nextrange = thisrange.next(1)

		if prevrange is not None:
			link = compose_querystring(internal_to_uri({**internalkeys,"timerange":prevrange}))
			html += "<a href='?" + link + "'><span class='stat_selector'>" + prevrange.desc() + "</span></a>"
			html += " « "
		if prevrange is not None or nextrange is not None:
			html += "<span class='stat_selector' style='opacity:0.5;'>" + thisrange.desc() + "</span>"
		if nextrange is not None:
			html += " » "
			link = compose_querystring(internal_to_uri({**internalkeys,"timerange":nextrange}))
			html += "<a href='?" + link + "'><span class='stat_selector'>" + nextrange.desc() + "</span></a>"

		html += "</div>"




	categories = [
		{
			"active":time,
			"options":{
				"Today":{"timerange":today()},
				"This Week":{"timerange":thisweek()},
				"This Month":{"timerange":thismonth()},
				"This Year":{"timerange":thisyear()},
				"All Time":{"timerange":alltime()}
			}
		},
		{
			"active":delimit,
			"options":{
				"Daily":{"step":"day","stepn":1},
				"Weekly":{"step":"week","stepn":1},
				"Fortnightly":{"step":"week","stepn":2},
				"Monthly":{"step":"month","stepn":1},
				"Quarterly":{"step":"month","stepn":3},
				"Yearly":{"step":"year","stepn":1}
			}
		},
		{
			"active":delimit,
			"options":{
				"Standard":{"trail":1},
				"Trailing":{"trail":2},
				"Long Trailing":{"trail":3},
				"Inert":{"trail":10},
				"Cumulative":{"trail":math.inf}
			}
		}

	]

	for c in categories:

		if c["active"]:

			optionlist = []
			for option in c["options"]:
				values = c["options"][option]
				link = "?" + compose_querystring(internal_to_uri({**internalkeys,**values}))

				if all(internalkeys.get(k) == values[k] for k in values):
					optionlist.append("<span class='stat_selector' style='opacity:0.5;'>" + option + "</span>")
				else:
					optionlist.append("<a href='" + link + "'><span class='stat_selector'>" + option + "</span></a>")

			html += "<div>" + " | ".join(optionlist) + "</div>"

	return html