1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Expanded start page

This commit is contained in:
Krateng 2019-02-02 18:08:30 +01:00
parent 562c796a92
commit 9a4afe4b1f
7 changed files with 161 additions and 30 deletions

View File

@ -146,6 +146,16 @@ def get_scrobbles():
return {"list":r} ##json can't be a list apparently???
@dbserver.route("/numscrobbles")
def get_scrobbles():
keys = FormsDict.decode(request.query)
r = db_query(artists=keys.getall("artist"),title=keys.get("title"),since=keys.get("since"),to=keys.get("to"),associated=(keys.get("associated")!=None))
r.reverse()
return {"amount":len(r)}
@dbserver.route("/tracks")
def get_tracks():
keys = FormsDict.decode(request.query)
@ -168,6 +178,10 @@ def get_artists():
return {"list":ARTISTS}
@dbserver.route("/amounts")
def get_amounts():
return {"scrobbles":len(SCROBBLES),"tracks":len(TRACKS),"artists":len(ARTISTS)}
@dbserver.route("/charts/artists")
def get_charts_artists():
since = request.query.get("since")
@ -733,6 +747,22 @@ def getTimestamps(f,t):
if isinstance(t, str) and t.lower() == "today":
tod = datetime.datetime.utcnow()
t = [tod.year,tod.month,tod.day]
if isinstance(f, str) and f.lower() == "month":
tod = datetime.datetime.utcnow()
f = [tod.year,tod.month]
if isinstance(t, str) and t.lower() == "month":
tod = datetime.datetime.utcnow()
t = [tod.year,tod.month]
if isinstance(f, str) and f.lower() == "year":
tod = datetime.datetime.utcnow()
f = [tod.year]
if isinstance(t, str) and t.lower() == "year":
tod = datetime.datetime.utcnow()
t = [tod.year]
if isinstance(f, str):

View File

@ -84,6 +84,7 @@ def static_image(pth):
@webserver.route("/<name:re:.*\\.css>")
@webserver.route("/<name:re:.*\\.png>")
@webserver.route("/<name:re:.*\\.jpeg>")
@webserver.route("/<name:re:.*\\.ico>")
def static(name):
return static_file("website/" + name,root="")

View File

@ -271,6 +271,21 @@ def getArtistInfo(artist):
result = apirequest(artist=artist)
cachedArtists[artist] = result["image"]
return result
def getTracksInfo(trackobjectlist):
threads = []
for track in trackobjectlist:
t = Thread(target=getTrackInfo,args=(track["artists"],track["title"],))
t.start()
threads.append(t)
for t in threads:
t.join()
return [getTrackInfo(t["artists"],t["title"]) for t in trackobjectlist]
def getArtistsInfo(artistlist):

BIN
website/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
website/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -8,39 +8,87 @@
</head>
<body>
<h1>Top Artists</h1>
<span class="stats">Scrobbles today</span> KEY_SCROBBLES_TODAY
<br/><span class="stats">Scrobbles this month</span> KEY_SCROBBLES_MONTH
<br/><span class="stats">Scrobbles overall</span> KEY_SCROBBLES_TOTAL
<h1><a href="/topartists">Top Artists</a></h1>
<table class="tiles_top">
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td>
<table class="tiles_2x2 tiles_sub">
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
</tr>
</table>
</td>
<td>
<table class="tiles_3x3 tiles_sub">
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
<td><div style="background-image:url('KEY_ARTISTIMAGE')"><span class="stats">KEY_POSITION_ARTIST</span> KEY_ARTISTLINK</div></td>
</tr>
</table>
</td>
</tr>
</table>
<h1><a href="/toptracks">Top Tracks</a></h1>
<table class="tiles_top">
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td>
<table class="tiles_2x2 tiles_sub">
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
</tr>
</table>
</td>
<td>
<table class="tiles_3x3 tiles_sub">
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
</tr>
<tr>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
<td><div style="background-image:url('KEY_TRACKIMAGE')"><span class="stats">KEY_POSITION_TRACK</span> KEY_TRACKLINK</div></td>
</tr>
</table>

View File

@ -3,32 +3,69 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, getArtistsInfo
from utilities import getArtistInfo, getArtistsInfo, getTracksInfo
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, keysToUrl, pickKeys, clean
clean(keys)
timekeys = pickKeys(keys,"since","to","in")
limitkeys = pickKeys(keys)
max_show = 15
posrange = ["#" + str(i) for i in range(1,max_show)]
#clean(keys)
#timekeys = pickKeys(keys,"since","to","in")
#limitkeys = pickKeys(keys)
# get chart data
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys))
# artists
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists")
db_data = json.loads(response.read())
charts = db_data["list"][:50]
charts = db_data["list"][:max_show]
topartist = charts[0]["artist"]
chartslist = [c["artist"] for c in charts]
artisttitles = [c["artist"] for c in charts]
#chartslistimg = [getArtistInfo(a).get("image") for a in chartslist]
chartslistimg = [info.get("image") for info in getArtistsInfo(chartslist)]
chartslistlink = [artistLink(a) for a in chartslist]
artistimages = [info.get("image") for info in getArtistsInfo(artisttitles)]
artistlinks = [artistLink(a) for a in artisttitles]
# get total amount of scrobbles
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys))
# tracks
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/tracks")
db_data = json.loads(response.read())
scrobblelist = db_data["list"]
scrobbles = len(scrobblelist)
charts = db_data["list"][:max_show]
trackobjects = [t["track"] for t in charts]
tracktitles = [t["title"] for t in trackobjects]
trackartists = [", ".join(t["artists"]) for t in trackobjects]
trackimages = [info.get("image") for info in getTracksInfo(trackobjects)]
tracklinks = [trackLink(t) for t in trackobjects]
# get scrobbles
#response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles")
#db_data = json.loads(response.read())
#scrobblelist = db_data["list"]
# get stats
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=today")
stats = json.loads(response.read())
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=month")
stats = json.loads(response.read())
scrobbles_month = "<a href='/scrobbles?since=month'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=year")
stats = json.loads(response.read())
scrobbles_year = "<a href='/scrobbles?since=year'>" + str(stats["amount"]) + "</a>"
response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles")
stats = json.loads(response.read())
scrobbles_total = "<a href='/scrobbles'>" + str(stats["amount"]) + "</a>"
#stats_tracks = "<a href='/toptracks'>" + str(stats["tracks"]) + "</a>"
#stats_artists = "<a href='/topartists'>" + str(stats["artists"]) + "</a>"
return {"KEY_ARTISTIMAGE":chartslistimg,"KEY_ARTISTNAME":chartslist,"KEY_ARTISTLINK":chartslistlink,"KEY_POSITION":["#" + str(i) for i in range(1,50)]}
return {"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_SCROBBLES_TODAY":scrobbles_today,"KEY_SCROBBLES_MONTH":scrobbles_month,"KEY_SCROBBLES_YEAR":scrobbles_year,"KEY_SCROBBLES_TOTAL":scrobbles_total}