mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Modularized tile charts on start page and added options for different ranges
This commit is contained in:
parent
1809da38e6
commit
b8fe71515c
@ -149,3 +149,94 @@ def module_artistcharts(max_=None,**kwargs):
|
||||
html += "</table>"
|
||||
|
||||
return (html, representative)
|
||||
|
||||
|
||||
def module_artistcharts_tiles(**kwargs) :
|
||||
|
||||
kwargs_filter = pickKeys(kwargs,"associated") #not used right now
|
||||
kwargs_time = pickKeys(kwargs,"since","to","within")
|
||||
|
||||
artists = database.get_charts_artists(**kwargs_filter,**kwargs_time)[:14]
|
||||
while len(artists)<14: artists.append(None)
|
||||
|
||||
i = 1
|
||||
|
||||
bigpart = [0,1,2,6,15]
|
||||
smallpart = [0,1,2,4,6,9,12,15]
|
||||
|
||||
|
||||
html = """<table class="tiles_top"><tr>"""
|
||||
|
||||
for e in artists:
|
||||
|
||||
|
||||
if i in bigpart:
|
||||
n = bigpart.index(i)
|
||||
html += """<td><table class="tiles_""" + str(n) + """x""" + str(n) + """ tiles_sub">"""
|
||||
|
||||
if i in smallpart:
|
||||
html += "<tr>"
|
||||
|
||||
rank = "#" + str(i) if e is not None else ""
|
||||
image = "/image?artist=" + urllib.parse.quote(e["artist"]) if e is not None else ""
|
||||
link = artistLink(e["artist"]) if e is not None else ""
|
||||
|
||||
html += """<td style="background-image:url('""" + image + """')"><span class="stats">""" + rank + "</span> <span>" + link + "</span></td>"
|
||||
|
||||
i += 1
|
||||
|
||||
if i in smallpart:
|
||||
html += "</tr>"
|
||||
|
||||
if i in bigpart:
|
||||
html += "</table></td>"
|
||||
|
||||
html += """</tr></table>"""
|
||||
|
||||
return html
|
||||
|
||||
|
||||
def module_trackcharts_tiles(**kwargs) :
|
||||
|
||||
kwargs_filter = pickKeys(kwargs,"artist","associated")
|
||||
kwargs_time = pickKeys(kwargs,"since","to","within")
|
||||
|
||||
tracks = database.get_charts_tracks(**kwargs_filter,**kwargs_time)[:14]
|
||||
while len(tracks)<14: tracks.append(None) #{"track":{"title":"","artists":[]}}
|
||||
|
||||
i = 1
|
||||
|
||||
bigpart = [0,1,2,6,15]
|
||||
smallpart = [0,1,2,4,6,9,12,15]
|
||||
|
||||
|
||||
html = """<table class="tiles_top"><tr>"""
|
||||
|
||||
for e in tracks:
|
||||
|
||||
|
||||
if i in bigpart:
|
||||
n = bigpart.index(i)
|
||||
html += """<td><table class="tiles_""" + str(n) + """x""" + str(n) + """ tiles_sub">"""
|
||||
|
||||
if i in smallpart:
|
||||
html += "<tr>"
|
||||
|
||||
rank = "#" + str(i) if e is not None else ""
|
||||
image = "/image?title=" + urllib.parse.quote(e["track"]["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in e["track"]["artists"]]) if e is not None else ""
|
||||
link = trackLink(e["track"]) if e is not None else ""
|
||||
|
||||
html += """<td style="background-image:url('""" + image + """')"><span class="stats">""" + rank + "</span> <span>" + link + "</span></td>"
|
||||
|
||||
i += 1
|
||||
|
||||
if i in smallpart:
|
||||
html += "</tr>"
|
||||
|
||||
if i in bigpart:
|
||||
html += "</table></td>"
|
||||
|
||||
html += """</tr></table>"""
|
||||
|
||||
return html
|
||||
|
||||
|
@ -101,6 +101,7 @@ def range_desc(since=None,to=None,within=None,short=False):
|
||||
# the 'short' var we pass down to some of the time_desc calls is a different one than the one here
|
||||
# the function-wide one indicates whether we want the 'in' 'from' etc at the start
|
||||
# the other one is if we want exact dates or weekdays etc
|
||||
# but we still hand it down because it makes sense
|
||||
|
||||
|
||||
if within is not None:
|
||||
@ -133,9 +134,9 @@ def range_desc(since=None,to=None,within=None,short=False):
|
||||
since,to = time_pad(since,to)
|
||||
if since == to:
|
||||
if len(since) == 3:
|
||||
sincestr = "on " + time_desc(since,short=True)
|
||||
sincestr = "on " + time_desc(since)
|
||||
else:
|
||||
sincestr = "in " + time_desc(since,short=True)
|
||||
sincestr = "in " + time_desc(since)
|
||||
shortsincestr = time_desc(since,short=True)
|
||||
tostr = ""
|
||||
elif _week(since,to):
|
||||
|
@ -232,7 +232,7 @@ def apirequest(artists=None,artist=None,title=None):
|
||||
except:
|
||||
pass
|
||||
|
||||
return {"image":""}
|
||||
return {"image":None}
|
||||
|
||||
# I think I've only just understood modules
|
||||
cachedTracks = {}
|
||||
@ -286,7 +286,7 @@ def getTrackInfo(artists,title):
|
||||
return result
|
||||
else:
|
||||
result = getArtistInfo(artist=artists[0])
|
||||
cachedTracks[(frozenset(artists),title)] = result["image"]
|
||||
#cachedTracks[(frozenset(artists),title)] = result["image"]
|
||||
return result
|
||||
|
||||
def getArtistInfo(artist):
|
||||
@ -315,8 +315,11 @@ def getArtistInfo(artist):
|
||||
pass
|
||||
|
||||
result = apirequest(artist=artist)
|
||||
if result.get("image") is not None:
|
||||
cachedArtists[artist] = result["image"]
|
||||
return result
|
||||
else:
|
||||
return {"image":""}
|
||||
|
||||
def getTracksInfo(trackobjectlist):
|
||||
|
||||
|
@ -109,11 +109,13 @@ a {
|
||||
|
||||
|
||||
|
||||
span.stat_selector_pulse {
|
||||
span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptracks {
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
**
|
||||
**
|
||||
|
@ -21,6 +21,34 @@
|
||||
}
|
||||
document.getElementById("selector_pulse_" + unit).setAttribute("style","opacity:0.5;")
|
||||
}
|
||||
|
||||
function showTopartists(unit) {
|
||||
modules = document.getElementsByClassName("stat_module_topartists")
|
||||
for (var i=0;i<modules.length;i++) {
|
||||
modules[i].setAttribute("style","display:none;")
|
||||
}
|
||||
document.getElementById("topartists_" + unit).setAttribute("style","")
|
||||
|
||||
selectors = document.getElementsByClassName("stat_selector_topartists")
|
||||
for (var i=0;i<selectors.length;i++) {
|
||||
selectors[i].setAttribute("style","")
|
||||
}
|
||||
document.getElementById("selector_topartists_" + unit).setAttribute("style","opacity:0.5;")
|
||||
}
|
||||
|
||||
function showToptracks(unit) {
|
||||
modules = document.getElementsByClassName("stat_module_toptracks")
|
||||
for (var i=0;i<modules.length;i++) {
|
||||
modules[i].setAttribute("style","display:none;")
|
||||
}
|
||||
document.getElementById("toptracks_" + unit).setAttribute("style","")
|
||||
|
||||
selectors = document.getElementsByClassName("stat_selector_toptracks")
|
||||
for (var i=0;i<selectors.length;i++) {
|
||||
selectors[i].setAttribute("style","")
|
||||
}
|
||||
document.getElementById("selector_toptracks_" + unit).setAttribute("style","opacity:0.5;")
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@ -28,100 +56,39 @@
|
||||
|
||||
<body>
|
||||
<h1><a href="/topartists?max=50">Top Artists</a></h1>
|
||||
<table class="tiles_top">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="tiles_1x1 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table class="tiles_2x2 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table class="tiles_3x3 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
<td style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> <span>KEY_ARTISTLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--All Time | This Year | This Month | This Week-->
|
||||
|
||||
|
||||
|
||||
<span onclick="showTopartists('week')" class="stat_selector_topartists" id="selector_topartists_week">This Week</span>
|
||||
| <span onclick="showTopartists('month')" class="stat_selector_topartists" id="selector_topartists_month">This Month</span>
|
||||
| <span onclick="showTopartists('year')" class="stat_selector_topartists" id="selector_topartists_year">This Year</span>
|
||||
| <span onclick="showTopartists('alltime')" class="stat_selector_topartists" id="selector_topartists_alltime" style="opacity:0.5;">All Time</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
<span class="stat_module_topartists" id="topartists_week" style="display:none;">KEY_TOPARTISTS_WEEK</span>
|
||||
<span class="stat_module_topartists" id="topartists_month" style="display:none;">KEY_TOPARTISTS_MONTH</span>
|
||||
<span class="stat_module_topartists" id="topartists_year" style="display:none;">KEY_TOPARTISTS_YEAR</span>
|
||||
<span class="stat_module_topartists" id="topartists_alltime">KEY_TOPARTISTS_TOTAL</span>
|
||||
|
||||
|
||||
|
||||
|
||||
<h1><a href="/toptracks?max=50">Top Tracks</a></h1>
|
||||
<table class="tiles_top">
|
||||
<tr>
|
||||
<td>
|
||||
<table class="tiles_1x1 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table class="tiles_2x2 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table class="tiles_3x3 tiles_sub">
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
<td style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> <span>KEY_TRACKLINK</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<span onclick="showToptracks('week')" class="stat_selector_toptracks" id="selector_toptracks_week">This Week</span>
|
||||
| <span onclick="showToptracks('month')" class="stat_selector_toptracks" id="selector_toptracks_month">This Month</span>
|
||||
| <span onclick="showToptracks('year')" class="stat_selector_toptracks" id="selector_toptracks_year">This Year</span>
|
||||
| <span onclick="showToptracks('alltime')" class="stat_selector_toptracks" id="selector_toptracks_alltime" style="opacity:0.5;">All Time</span>
|
||||
|
||||
<br/><br/>
|
||||
|
||||
<span class="stat_module_toptracks" id="toptracks_week" style="display:none;">KEY_TOPTRACKS_WEEK</span>
|
||||
<span class="stat_module_toptracks" id="toptracks_month" style="display:none;">KEY_TOPTRACKS_MONTH</span>
|
||||
<span class="stat_module_toptracks" id="toptracks_year" style="display:none;">KEY_TOPTRACKS_YEAR</span>
|
||||
<span class="stat_module_toptracks" id="toptracks_alltime">KEY_TOPTRACKS_TOTAL</span>
|
||||
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@ import urllib
|
||||
from datetime import datetime, timedelta
|
||||
import database
|
||||
|
||||
from htmlmodules import module_scrobblelist, module_pulse
|
||||
from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles
|
||||
|
||||
|
||||
def instructions(keys):
|
||||
@ -15,19 +15,28 @@ def instructions(keys):
|
||||
# get chart data
|
||||
|
||||
# artists
|
||||
charts = database.get_charts_artists()[:max_show]
|
||||
artisttitles = [c["artist"] for c in charts]
|
||||
artistimages = ["/image?artist=" + urllib.parse.quote(a) for a in artisttitles]
|
||||
artistlinks = [artistLink(a) for a in artisttitles]
|
||||
# charts = database.get_charts_artists()[:max_show]
|
||||
# artisttitles = [c["artist"] for c in charts]
|
||||
# artistimages = ["/image?artist=" + urllib.parse.quote(a) for a in artisttitles]
|
||||
# artistlinks = [artistLink(a) for a in artisttitles]
|
||||
|
||||
topartists_total = module_artistcharts_tiles()
|
||||
topartists_year = module_artistcharts_tiles(since="year")
|
||||
topartists_month = module_artistcharts_tiles(since="month")
|
||||
#topartists_week = module_artistcharts_tiles(since="week")
|
||||
|
||||
|
||||
# tracks
|
||||
charts = database.get_charts_tracks()[:max_show]
|
||||
trackobjects = [t["track"] for t in charts]
|
||||
tracktitles = [t["title"] for t in trackobjects]
|
||||
trackimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]]) for t in trackobjects]
|
||||
tracklinks = [trackLink(t) for t in trackobjects]
|
||||
# charts = database.get_charts_tracks()[:max_show]
|
||||
# trackobjects = [t["track"] for t in charts]
|
||||
# tracktitles = [t["title"] for t in trackobjects]
|
||||
# trackimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]]) for t in trackobjects]
|
||||
# tracklinks = [trackLink(t) for t in trackobjects]
|
||||
|
||||
toptracks_total = module_trackcharts_tiles()
|
||||
toptracks_year = module_trackcharts_tiles(since="year")
|
||||
toptracks_month = module_trackcharts_tiles(since="month")
|
||||
#toptracks_week = module_trackcharts_tiles(since="week")
|
||||
|
||||
# get scrobbles
|
||||
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
|
||||
@ -69,10 +78,14 @@ def instructions(keys):
|
||||
html_pulse_months = module_pulse(max_=12,since=first_month,step="month",trail=1)
|
||||
html_pulse_years = module_pulse(max_=10,since=first_year,step="year",trail=1)
|
||||
|
||||
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 = [{"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_ARTISTIMAGE":artistimages,"KEY_ARTISTNAME":artisttitles,"KEY_ARTISTLINK":artistlinks,"KEY_POSITION_ARTIST":posrange,
|
||||
"KEY_TRACKIMAGE":trackimages,"KEY_TRACKNAME":tracktitles,"KEY_TRACKLINK":tracklinks,"KEY_POSITION_TRACK":posrange,
|
||||
replace = {
|
||||
# "KEY_ARTISTIMAGE":artistimages,"KEY_ARTISTNAME":artisttitles,"KEY_ARTISTLINK":artistlinks,"KEY_POSITION_ARTIST":posrange,
|
||||
# "KEY_TRACKIMAGE":trackimages,"KEY_TRACKNAME":tracktitles,"KEY_TRACKLINK":tracklinks,"KEY_POSITION_TRACK":posrange,
|
||||
"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_SCROBBLES_TODAY":scrobbles_today,"KEY_SCROBBLES_MONTH":scrobbles_month,"KEY_SCROBBLES_YEAR":scrobbles_year,"KEY_SCROBBLES_TOTAL":scrobbles_total,
|
||||
#"KEY_SCROBBLE_TIME":scrobbletimes,"KEY_SCROBBLE_ARTISTS":scrobbleartists,"KEY_SCROBBLE_TITLE":scrobbletracklinks,"KEY_SCROBBLE_IMAGE":scrobbleimages,
|
||||
"KEY_SCROBBLES":html_scrobbles,
|
||||
|
Loading…
Reference in New Issue
Block a user