From 46d0874dfc55fb015ad6e9b4b18d1a9539ff731d Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 21 Feb 2019 09:43:35 +0100 Subject: [PATCH] No more internal communication via HTTP --- database.py | 4 ++++ server.py | 2 +- website/artist.py | 2 +- website/issues.py | 7 +++---- website/pulse.py | 12 ++++-------- website/scrobbles.py | 3 +-- website/start.py | 2 +- website/topartists.py | 45 +++---------------------------------------- website/toptracks.py | 44 ++---------------------------------------- website/track.py | 39 ++----------------------------------- 10 files changed, 22 insertions(+), 138 deletions(-) diff --git a/database.py b/database.py index 23006aa..1738ab1 100644 --- a/database.py +++ b/database.py @@ -631,6 +631,10 @@ def newrule(): @dbserver.route("/issues") +def issues_external(): #probably not even needed + return issues() + + def issues(): combined = [] duplicates = [] diff --git a/server.py b/server.py index 50b097f..5322306 100755 --- a/server.py +++ b/server.py @@ -133,7 +133,7 @@ def static_html(name): # If a python file exists, it provides the replacement dict for the html file if os.path.exists("website/" + name + ".py"): #txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT) - txt_keys,resources = SourceFileLoader(name,"website/" + name + ".py").load_module().instructions(keys,DATABASE_PORT) + txt_keys,resources = SourceFileLoader(name,"website/" + name + ".py").load_module().instructions(keys) # add headers for server push for resource in resources: diff --git a/website/artist.py b/website/artist.py index 7a51fab..a7b8618 100644 --- a/website/artist.py +++ b/website/artist.py @@ -2,7 +2,7 @@ import urllib import database -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo from htmlgenerators import clean, artistLink, artistLinks, KeySplit from htmlmodules import module_pulse, module_trackcharts diff --git a/website/issues.py b/website/issues.py index 9cf191c..bed56a6 100644 --- a/website/issues.py +++ b/website/issues.py @@ -1,11 +1,10 @@ import urllib -import json +import database from htmlgenerators import artistLink -def instructions(keys,dbport): +def instructions(keys): - response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/issues") - db_data = json.loads(response.read()) + db_data = database.issues() i = 0 html = "" diff --git a/website/pulse.py b/website/pulse.py index 3401a3a..e25d97e 100644 --- a/website/pulse.py +++ b/website/pulse.py @@ -1,8 +1,8 @@ import urllib -import json +import database -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo, getTrackInfo from htmlgenerators import getTimeDesc, artistLink, artistLinks, trackLink, scrobblesLink, keysToUrl, getRangeDesc, KeySplit from htmlmodules import module_pulse @@ -22,9 +22,8 @@ def instructions(keys,dbport): #limitkey["artist"], limitkey["associated"] = keys.get("artist"), (keys.get("associated")!=None) limitstring += "of " + artistLink(filterkeys.get("artist")) if filterkeys.get("associated"): - response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"])) - db_data = json.loads(response.read()) - moreartists = db_data["associated"] + data = database.artistInfo(filterkeys["artist"]) + moreartists = data["associated"] if moreartists != []: limitstring += " including " + artistLinks(moreartists) + "" @@ -34,9 +33,6 @@ def instructions(keys,dbport): imgurl = getTrackInfo(filterkeys.get("track")["artists"],filterkeys.get("track")["title"]).get("image") elif filterkeys.get("artist") is not None: imgurl = getArtistInfo(keys.get("artist")).get("image") - #elif (len(scrobbles) != 0): - # imgurl = getTrackInfo(scrobbles[0]["artists"],scrobbles[0]["title"]).get("image") - # #imgurl = getArtistInfo(scrobbles[0]["artists"][0]).get("image") else: imgurl = "" diff --git a/website/scrobbles.py b/website/scrobbles.py index 32ddc24..68cee8e 100644 --- a/website/scrobbles.py +++ b/website/scrobbles.py @@ -1,9 +1,8 @@ import urllib -import json import database -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo, getTrackInfo from htmlgenerators import artistLink, artistLinks, trackLink, KeySplit from htmlmodules import module_scrobblelist diff --git a/website/start.py b/website/start.py index 1f2449c..436b94c 100644 --- a/website/start.py +++ b/website/start.py @@ -5,7 +5,7 @@ import database from htmlmodules import module_scrobblelist, module_pulse -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistsInfo, getTracksInfo from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, scrobblesLink, keysToUrl, pickKeys, clean, getTimeDesc, getRangeDesc diff --git a/website/topartists.py b/website/topartists.py index cefc89d..a7c3552 100644 --- a/website/topartists.py +++ b/website/topartists.py @@ -1,62 +1,23 @@ import urllib -import json -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo from htmlgenerators import KeySplit from htmlmodules import module_artistcharts - -# clean(keys) -# timekeys = pickKeys(keys,"since","to","in") -# limitkeys = pickKeys(keys) + _, timekeys, _, amountkeys = KeySplit(keys) - # get chart data -# response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys)) -# db_data = json.loads(response.read()) -# charts = db_data["list"][:50] -# topartist = charts[0]["artist"] - -# info = getArtistInfo(topartist) -# imgurl = info.get("image") - - - # get total amount of scrobbles - #response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys)) - #db_data = json.loads(response.read()) - #scrobblelist = db_data["list"] - #scrobbles = len(scrobblelist) - - html_charts, rep = module_artistcharts(**amountkeys,**timekeys) if rep is not None: imgurl = getArtistInfo(rep).get("image") else: imgurl = "" + pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - # build list -# maxbar = charts[0]["scrobbles"] -# -# i = 1 -# html = "
" -# for e in charts: -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# i += 1 -# html += "
#" + str(i) + "" + artistLink(e["artist"]) -# if (e["counting"] != []): -# html += " incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "" -# html += "" + scrobblesArtistLink(e["artist"],timekeys,amount=e["scrobbles"],associated=True) + "" + scrobblesArtistLink(e["artist"],timekeys,percent=e["scrobbles"]*100/maxbar,associated=True) + "
" - - replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_ARTISTLIST":html_charts} diff --git a/website/toptracks.py b/website/toptracks.py index ec0bc8e..8611fc5 100644 --- a/website/toptracks.py +++ b/website/toptracks.py @@ -1,43 +1,17 @@ import urllib -import json -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo, getTrackInfo from htmlgenerators import artistLink, KeySplit from htmlmodules import module_trackcharts -# clean(keys) -# timekeys = pickKeys(keys,"since","to","in") -# limitkeys = pickKeys(keys,"artist") - filterkeys, timekeys, _, amountkeys = KeySplit(keys) limitstring = "" - - if filterkeys.get("artist") is not None: - topartist = filterkeys.get("artist") -# #limitstring += "by " + ", ".join([artistLink(a) for a in keys.getall("artist")]) - limitstring = "by " + artistLink(filterkeys.get("artist")) -# info = getArtistInfo(topartist) -# imgurl = info.get("image") -# else: -# #topartist = charts[0]["track"]["artists"][0] #for now -# info = getTrackInfo(charts[0]["track"]["artists"],charts[0]["track"]["title"]) -# imgurl = info.get("image") - - - - # get total amount of scrobbles -# response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys)) -# db_data = json.loads(response.read()) -# scrobblelist = db_data["list"] -# scrobbles = len(scrobblelist) - - html_charts, rep = module_trackcharts(**amountkeys,**timekeys,**filterkeys) @@ -51,21 +25,7 @@ def instructions(keys,dbport): pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - # build list -# maxbar = charts[0]["scrobbles"] -# -# i = 1 -# html = "" -# for e in charts: -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# i += 1 -# html += "
#" + str(i) + "" + artistLinks(e["track"]["artists"]) + "" + trackLink(e["track"]) + "" + scrobblesTrackLink(e["track"],timekeys,amount=e["scrobbles"]) + "" + scrobblesTrackLink(e["track"],timekeys,percent=e["scrobbles"]*100/maxbar) + "
" + replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_TRACKLIST":html_charts,"KEY_LIMITS":limitstring} diff --git a/website/track.py b/website/track.py index 202ad84..4ddc633 100644 --- a/website/track.py +++ b/website/track.py @@ -2,9 +2,9 @@ import urllib import database -def instructions(keys,dbport): +def instructions(keys): from utilities import getArtistInfo, getTrackInfo - from htmlgenerators import clean, artistLink, artistLinks, trackLink, scrobblesTrackLink, keysToUrl, pickKeys, getTimeDesc, getRangeDesc, scrobblesLink, KeySplit + from htmlgenerators import artistLinks, keysToUrl, KeySplit from htmlmodules import module_scrobblelist, module_pulse @@ -19,44 +19,9 @@ def instructions(keys,dbport): pos = "#" + str(data["position"]) - #response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/scrobbles?" + keysToUrl(limitkeys)) - #db_data = json.loads(response.read()) - #scrobbles = db_data["list"] - - - # build list -# html = "" -# for s in scrobbles: -# html += "" -# html += "" -# html += "" -# html += "" -# html += "" -# html += "
" + getTimeDesc(s["time"]) + "" + artistLinks(s["artists"]) + "" + trackLink({"artists":s["artists"],"title":s["title"]}) + "
" html_scrobbles, _, _ = module_scrobblelist(track=track,max_=100) - # pulse -# response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/pulse?step=year&trail=1&" + keysToUrl(limitkeys)) -# db_data = json.loads(response.read()) -# terms = db_data["list"] - - # build list -# maxbar = max([t["scrobbles"] for t in terms]) - -# html_pulse = "" -# for t in terms: -# fromstr = "/".join([str(e) for e in t["from"]]) -# tostr = "/".join([str(e) for e in t["to"]]) -# html_pulse += "" -# #html += "" -# #html += "" -# html_pulse += "" -# html_pulse += "" -# html_pulse += "" -# html_pulse += "" -# html_pulse += "
" + fromstr + "" + tostr + "" + getRangeDesc(t["from"],t["to"]) + "" + scrobblesLink({"since":fromstr,"to":tostr},amount=t["scrobbles"],track=trackobject) + "" + scrobblesLink({"since":fromstr,"to":tostr},percent=t["scrobbles"]*100/maxbar,track=trackobject) + "
" - html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1)