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

Cleaning up

This commit is contained in:
Krateng 2019-02-21 00:13:18 +01:00
parent f1007d6da5
commit efd4b89da1
6 changed files with 26 additions and 96 deletions

View File

@ -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

View File

@ -32,9 +32,6 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
i = 0
html = "<table class='list'>"
for s in scrobbles:
i += 1
if max_ is not None and i>=max_:
break
html += "<tr>"
html += "<td class='time'>" + getTimeDesc(s["time"],short=shortTimeDesc) + "</td>"
@ -44,6 +41,10 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
html += "</tr>"
i += 1
if max_ is not None and i>=max_:
break
html += "</table>"

View File

@ -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
}

View File

@ -1,5 +1,4 @@
import urllib
import json
import database

View File

@ -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 = "<a href='/scrobbles?since=today'>" + str(stats["amount"]) + "</a>"
amount = database.get_scrobbles_num(since="today")
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount) + "</a>"
response = urllib.request.urlopen("http://[::1]:" +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://[::1]:" +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://[::1]:" +str(dbport) + "/numscrobbles")
stats = json.loads(response.read())
scrobbles_total = "<a href='/scrobbles'>" + str(stats["amount"]) + "</a>"
amount = database.get_scrobbles_num(since="month")
scrobbles_month = "<a href='/scrobbles?since=month'>" + str(amount) + "</a>"
amount = database.get_scrobbles_num(since="year")
scrobbles_year = "<a href='/scrobbles?since=year'>" + str(amount) + "</a>"
amount = database.get_scrobbles_num()
scrobbles_total = "<a href='/scrobbles'>" + str(amount) + "</a>"
# 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,

View File

@ -1,5 +1,4 @@
import urllib
import json
import database