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

No more internal communication via HTTP

This commit is contained in:
Krateng 2019-02-21 09:43:35 +01:00
parent efd4b89da1
commit 46d0874dfc
10 changed files with 22 additions and 138 deletions

View File

@ -631,6 +631,10 @@ def newrule():
@dbserver.route("/issues")
def issues_external(): #probably not even needed
return issues()
def issues():
combined = []
duplicates = []

View File

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

View File

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

View File

@ -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 = "<table class='list'>"

View File

@ -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 += " <span class='extra'>including " + artistLinks(moreartists) + "</span>"
@ -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 = ""

View File

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

View File

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

View File

@ -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 = "<table class='list'>"
# for e in charts:
# html += "<tr>"
# html += "<td class='rank'>#" + str(i) + "</td>"
# html += "<td class='artist'>" + artistLink(e["artist"])
# if (e["counting"] != []):
# html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
# html += "</td>"
# html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],timekeys,amount=e["scrobbles"],associated=True) + "</td>"
# html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],timekeys,percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
# html += "</tr>"
# i += 1
# html += "</table>"
replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_ARTISTLIST":html_charts}

View File

@ -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 = "<table class='list'>"
# for e in charts:
# html += "<tr>"
# html += "<td class='rank'>#" + str(i) + "</td>"
# html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
# html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
# html += "<td class='amount'>" + scrobblesTrackLink(e["track"],timekeys,amount=e["scrobbles"]) + "</td>"
# html += "<td class='bar'>" + scrobblesTrackLink(e["track"],timekeys,percent=e["scrobbles"]*100/maxbar) + "</td>"
# html += "</tr>"
# i += 1
# html += "</table>"
replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_TRACKLIST":html_charts,"KEY_LIMITS":limitstring}

View File

@ -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 = "<table class='list'>"
# for s in scrobbles:
# html += "<tr>"
# html += "<td class='time'>" + getTimeDesc(s["time"]) + "</td>"
# html += "<td class='artists'>" + artistLinks(s["artists"]) + "</td>"
# html += "<td class='title'>" + trackLink({"artists":s["artists"],"title":s["title"]}) + "</td>"
# html += "</tr>"
# html += "</table>"
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 = "<table class='list'>"
# for t in terms:
# fromstr = "/".join([str(e) for e in t["from"]])
# tostr = "/".join([str(e) for e in t["to"]])
# html_pulse += "<tr>"
# #html += "<td>" + fromstr + "</td>"
# #html += "<td>" + tostr + "</td>"
# html_pulse += "<td>" + getRangeDesc(t["from"],t["to"]) + "</td>"
# html_pulse += "<td class='amount'>" + scrobblesLink({"since":fromstr,"to":tostr},amount=t["scrobbles"],track=trackobject) + "</td>"
# html_pulse += "<td class='bar'>" + scrobblesLink({"since":fromstr,"to":tostr},percent=t["scrobbles"]*100/maxbar,track=trackobject) + "</td>"
# html_pulse += "</tr>"
# html_pulse += "</table>"
html_pulse = module_pulse(track=track,step="year",stepn=1,trail=1)