diff --git a/database.py b/database.py
index 57e5c50..23006aa 100644
--- a/database.py
+++ b/database.py
@@ -198,7 +198,7 @@ def get_scrobbles_num_external():
return {"amount":result}
def get_scrobbles_num(**keys):
- r = db_query(**{k:keys[k] for k in keys if k in ["artists","title","since","to","within","associated"]})
+ r = db_query(**{k:keys[k] for k in keys if k in ["artist","track","artists","title","since","to","within","associated"]})
return len(r)
# DEPRECATED
diff --git a/htmlmodules.py b/htmlmodules.py
index 7c07bc7..0fc4517 100644
--- a/htmlmodules.py
+++ b/htmlmodules.py
@@ -32,9 +32,6 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
i = 0
html = "
"
for s in scrobbles:
- i += 1
- if max_ is not None and i>=max_:
- break
html += ""
html += "" + getTimeDesc(s["time"],short=shortTimeDesc) + " | "
@@ -44,6 +41,10 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
html += "" + trackLink({"artists":s["artists"],"title":s["title"]}) + " | "
html += "
"
+ i += 1
+ if max_ is not None and i>=max_:
+ break
+
html += "
"
diff --git a/utilities.py b/utilities.py
index d1c84e3..13e20bf 100644
--- a/utilities.py
+++ b/utilities.py
@@ -188,8 +188,8 @@ def apirequest(artists=None,artist=None,title=None):
"name":"lastfm",
"artisturl":"https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={artist}&api_key=" + apikey + "&format=json",
"trackurl":"https://ws.audioscrobbler.com/2.0/?method=track.getinfo&track={title}&artist={artist}&api_key=" + apikey + "&format=json",
- "result_artist_imgurl":lambda data:data["artist"]["image"][2]["#text"],
- "result_track_imgurl":lambda data:data["track"]["album"]["image"][2]["#text"]
+ "result_artist_imgurl":lambda data:data["artist"]["image"][3]["#text"],
+ "result_track_imgurl":lambda data:data["track"]["album"]["image"][3]["#text"]
#"result_artist_desc":lambda data:data["artist"]["bio"]["summary"],
#"result_track_desc":lambda data:None
}
diff --git a/website/artist.py b/website/artist.py
index 5443c71..7a51fab 100644
--- a/website/artist.py
+++ b/website/artist.py
@@ -1,5 +1,4 @@
import urllib
-import json
import database
diff --git a/website/start.py b/website/start.py
index c0232b5..1f2449c 100644
--- a/website/start.py
+++ b/website/start.py
@@ -1,102 +1,50 @@
import urllib
-import json
-from threading import Thread
from datetime import datetime
-#import database
+import database
from htmlmodules import module_scrobblelist, module_pulse
-
-def getpictures(ls,result,tracks=False):
- from utilities import getArtistsInfo, getTracksInfo
- if tracks:
- for element in getTracksInfo(ls):
- result.append(element.get("image"))
- else:
- for element in getArtistsInfo(ls):
- result.append(element.get("image"))
def instructions(keys,dbport):
from utilities import getArtistsInfo, getTracksInfo
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, scrobblesLink, keysToUrl, pickKeys, clean, getTimeDesc, getRangeDesc
- max_show = 15
- posrange = ["#" + str(i) for i in range(1,max_show)]
-
-
- #clean(keys)
- #timekeys = pickKeys(keys,"since","to","in")
- #limitkeys = pickKeys(keys)
-
+ max_show = 14
+ posrange = ["#" + str(i) for i in range(1,max_show+1)]
+
# get chart data
# artists
- response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/artists")
- db_data = json.loads(response.read())
- charts = db_data["list"][:max_show]
- #charts = database.get_charts_artists()[:max_show]
- topartist = charts[0]["artist"]
-
+ charts = database.get_charts_artists()[:max_show]
artisttitles = [c["artist"] for c in charts]
- #artistimages = []
- #t1 = Thread(target=getpictures,args=(artisttitles,artistimages,))
- #t1.start()
artistimages = ["/image?artist=" + urllib.parse.quote(a) for a in artisttitles]
- #artistimages = [info.get("image") for info in getArtistsInfo(artisttitles)]
artistlinks = [artistLink(a) for a in artisttitles]
# tracks
- response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/tracks")
- db_data = json.loads(response.read())
- charts = db_data["list"][:max_show]
- #charts = database.get_charts_trackss()[:max_show]
-
+ charts = database.get_charts_tracks()[: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 = []
- #t2 = Thread(target=getpictures,args=(trackobjects,trackimages,),kwargs={"tracks":True})
- #t2.start()
trackimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in 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://[::1]:" + str(dbport) + "/scrobbles?max=50")
-# db_data = json.loads(response.read())
-# scrobblelist = db_data["list"]
-# #scrobblelist = database.get_scrobbles(max=50)
-# scrobbletrackobjects = scrobblelist #ignore the extra time attribute, the format should still work
-# scrobbleartists = [", ".join([artistLink(a) for a in s["artists"]]) for s in scrobblelist]
-# scrobbletitles = [s["title"] for s in scrobblelist]
-# scrobbletimes = [getTimeDesc(s["time"],short=True) for s in scrobblelist]
-# scrobbleimages = []
-# t3 = Thread(target=getpictures,args=(scrobbletrackobjects,scrobbleimages,),kwargs={"tracks":True})
-# t3.start()
-# #scrobbleimages = [info.get("image") for info in getTracksInfo(scrobbletrackobjects)]
-# scrobbletracklinks = [trackLink(t) for t in scrobbletrackobjects]
-
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
# get stats
- response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=today")
- stats = json.loads(response.read())
- scrobbles_today = "" + str(stats["amount"]) + ""
+ amount = database.get_scrobbles_num(since="today")
+ scrobbles_today = "" + str(amount) + ""
- response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=month")
- stats = json.loads(response.read())
- scrobbles_month = "" + str(stats["amount"]) + ""
-
- response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles?since=year")
- stats = json.loads(response.read())
- scrobbles_year = "" + str(stats["amount"]) + ""
-
- response = urllib.request.urlopen("http://[::1]:" +str(dbport) + "/numscrobbles")
- stats = json.loads(response.read())
- scrobbles_total = "" + str(stats["amount"]) + ""
+ amount = database.get_scrobbles_num(since="month")
+ scrobbles_month = "" + str(amount) + ""
+
+ amount = database.get_scrobbles_num(since="year")
+ scrobbles_year = "" + str(amount) + ""
+
+ amount = database.get_scrobbles_num()
+ scrobbles_total = "" + str(amount) + ""
# get pulse
@@ -107,27 +55,10 @@ def instructions(keys,dbport):
# this is literally the ugliest piece of code i have written in my entire feckin life
# good lord
-# response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/pulse?step=month&trail=1&since=" + dts)
-# db_data = json.loads(response.read())
-# terms = db_data["list"]
-
-# maxbar = max([t["scrobbles"] for t in terms])
-# #pulse_fromdates = ["/".join([str(e) for e in t["from"]]) for t in terms]
-# #pulse_todates = ["/".join([str(e) for e in t["to"]]) for t in terms]
-# pulse_rangedescs = [getRangeDesc(t["from"],t["to"]) for t in terms]
-# pulse_amounts = [scrobblesLink({"since":"/".join([str(e) for e in t["from"]]),"to":"/".join([str(e) for e in t["to"]])},amount=t["scrobbles"]) for t in terms]
-# pulse_bars = [scrobblesLink({"since":"/".join([str(e) for e in t["from"]]),"to":"/".join([str(e) for e in t["to"]])},percent=t["scrobbles"]*100/maxbar) for t in terms]
-
html_pulse = module_pulse(max_=12,since=dts,step="month",trail=1)
-
-
-
- #t1.join()
- #t2.join()
- #t3.join()
-
- #pushresources = [{"file":img,"type":"image"} for img in artistimages + trackimages + scrobbleimages if img.startswith("/")]
- pushresources = []
+
+
+ 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
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,
diff --git a/website/track.py b/website/track.py
index 5949b50..202ad84 100644
--- a/website/track.py
+++ b/website/track.py
@@ -1,5 +1,4 @@
import urllib
-import json
import database