diff --git a/database.py b/database.py index 3f49998..83ee0a6 100644 --- a/database.py +++ b/database.py @@ -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): diff --git a/server.py b/server.py index f3fe41f..b8ca71c 100755 --- a/server.py +++ b/server.py @@ -84,6 +84,7 @@ def static_image(pth): @webserver.route("/") @webserver.route("/") @webserver.route("/") +@webserver.route("/") def static(name): return static_file("website/" + name,root="") diff --git a/utilities.py b/utilities.py index d17d1cf..cea4f92 100644 --- a/utilities.py +++ b/utilities.py @@ -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): diff --git a/website/favicon.ico b/website/favicon.ico new file mode 100644 index 0000000..03e8803 Binary files /dev/null and b/website/favicon.ico differ diff --git a/website/favicon.png b/website/favicon.png new file mode 100644 index 0000000..6ef8fd5 Binary files /dev/null and b/website/favicon.png differ diff --git a/website/start.html b/website/start.html index bf424ff..ff3cf0d 100644 --- a/website/start.html +++ b/website/start.html @@ -8,39 +8,87 @@ - -

Top Artists

+ + Scrobbles today KEY_SCROBBLES_TODAY +
Scrobbles this month KEY_SCROBBLES_MONTH +
Scrobbles overall KEY_SCROBBLES_TOTAL + +

Top Artists

- + + +
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
- - + + - - + +
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
- - - + + + - - - + + + - - - + + + + +
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
KEY_POSITION_ARTIST KEY_ARTISTLINK
+ +
+ + + + + + +

Top Tracks

+ + + + +
KEY_POSITION_TRACK KEY_TRACKLINK
+ + + + + + + + + +
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
+
+ + + + + + + + + + + + + + +
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
KEY_POSITION_TRACK KEY_TRACKLINK
diff --git a/website/start.py b/website/start.py index aa89b06..d598f1b 100644 --- a/website/start.py +++ b/website/start.py @@ -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 = "" + str(stats["amount"]) + "" + + response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=month") + stats = json.loads(response.read()) + scrobbles_month = "" + str(stats["amount"]) + "" + + response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles?since=year") + stats = json.loads(response.read()) + scrobbles_year = "" + str(stats["amount"]) + "" + + response = urllib.request.urlopen("http://localhost:" +str(dbport) + "/numscrobbles") + stats = json.loads(response.read()) + scrobbles_total = "" + str(stats["amount"]) + "" + #stats_tracks = "" + str(stats["tracks"]) + "" + #stats_artists = "" + str(stats["artists"]) + "" - 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}