diff --git a/htmlmodules.py b/htmlmodules.py index e62a75a..90076e3 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -149,3 +149,94 @@ def module_artistcharts(max_=None,**kwargs): html += "" 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 = """""" + + for e in artists: + + + if i in bigpart: + n = bigpart.index(i) + html += """" + + html += """
""" + + if i in smallpart: + html += "" + + 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 += """" + + i += 1 + + if i in smallpart: + html += "" + + if i in bigpart: + html += "
""" + rank + " " + link + "
""" + + 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 = """""" + + for e in tracks: + + + if i in bigpart: + n = bigpart.index(i) + html += """" + + html += """
""" + + if i in smallpart: + html += "" + + 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 += """" + + i += 1 + + if i in smallpart: + html += "" + + if i in bigpart: + html += "
""" + rank + " " + link + "
""" + + return html + diff --git a/malojatime.py b/malojatime.py index 42acd00..c6f9062 100644 --- a/malojatime.py +++ b/malojatime.py @@ -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): diff --git a/utilities.py b/utilities.py index 13e20bf..ebec4f1 100644 --- a/utilities.py +++ b/utilities.py @@ -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) - cachedArtists[artist] = result["image"] - return result + if result.get("image") is not None: + cachedArtists[artist] = result["image"] + return result + else: + return {"image":""} def getTracksInfo(trackobjectlist): diff --git a/website/maloja.css b/website/maloja.css index ab135d7..abaee5e 100644 --- a/website/maloja.css +++ b/website/maloja.css @@ -109,11 +109,13 @@ a { -span.stat_selector_pulse { +span.stat_selector_pulse,span.stat_selector_topartists,span.stat_selector_toptracks { cursor:pointer; } + + /* ** ** diff --git a/website/start.html b/website/start.html index 98c39b0..bca8a85 100644 --- a/website/start.html +++ b/website/start.html @@ -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 @@ -28,101 +56,40 @@

Top Artists

- - - - - - -
- - - - -
KEY_POSITION_ARTIST KEY_ARTISTLINK
-
- - - - - - - - - -
KEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINK
-
- - - - - - - - - - - - - - - - -
KEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINKKEY_POSITION_ARTIST KEY_ARTISTLINK
- -
+ + This Week + | This Month + | This Year + | All Time + +

+ + + + + KEY_TOPARTISTS_TOTAL +

Top Tracks

- - - - - - -
- - - - -
KEY_POSITION_TRACK KEY_TRACKLINK
-
- - - - - - - - - -
KEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINK
-
- - - - - - - - - - - - - - - - -
KEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINKKEY_POSITION_TRACK KEY_TRACKLINK
- -
+ This Week + | This Month + | This Year + | All Time + +

+ + + + + KEY_TOPTRACKS_TOTAL + diff --git a/website/start.py b/website/start.py index cff4e76..f1907b4 100644 --- a/website/start.py +++ b/website/start.py @@ -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,