Simplified some of the webpage building logic

This commit is contained in:
Krateng 2018-12-22 12:47:49 +01:00
parent 7465eadf83
commit eb9c9b2f69
7 changed files with 52 additions and 47 deletions

View File

@ -23,11 +23,11 @@ class CleanerAgent:
artists = self.parseArtists(self.removespecial(artist))
title = self.parseTitle(self.removespecial(title))
(title,moreartists) = self.parseTitleForArtists(title)
artists += moreartists
artists += moreartists
artists = list(set(artists))
artists.sort()
return (list(set(artists)),title)
return (artists,title)
def removespecial(self,s):
s = s.replace("\t","").replace("","").replace("\n","")

View File

@ -18,7 +18,6 @@ for fn in os.listdir("scrobbles/"):
a = a.replace("",";")
(al,t) = wendigo.fullclean(a,t)
al.sort()
a = "".join(al)
fnew.write(r1 + a + r2 + t + r3 + "\n")
#print("Artists: " + a)

View File

@ -3,7 +3,7 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo
from utilities import getArtistInfo, artistLink
info = getArtistInfo(keys["artist"])
@ -18,32 +18,28 @@ def replacedict(keys,dbport):
credited = db_data.get("replace")
includestr = " "
if credited is not None:
includestr = "Competing under <a href=/artist?artist=" + urllib.parse.quote(credited) + ">" + credited + "</a> (" + pos + ")"
includestr = "Competing under " + artistLink(credited) + " (" + pos + ")"
pos = ""
included = db_data.get("associated")
if included is not None and included != []:
includestr = "associated: "
for a in included:
includestr += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
includestr = includestr[:-2]
#for a in included:
includestr += ", ".join([artistLink(a) for a in included]) #"<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
#includestr = includestr[:-2]
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/tracks?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
tracks = []
for e in db_data["list"]:
html = "<td class='artists'>"
for a in e["artists"]:
html += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
html = html[:-2]
html += "</td><td class='title'>" + e["title"] + "</td>"
tracks.append(html)
trackshtml = "<table class='list'>"
for t in tracks:
trackshtml += "<tr>"
trackshtml += t
trackshtml += "</tr>"
trackshtml += "</table>"
html = "<table class='list'>"
for e in db_data["list"]:
html += "<tr>"
html += "<td class='artists'>"
links = [artistLink(a) for a in e["artists"]]
html += ", ".join(links)
html += "</td><td class='title'>" + e["title"] + "</td>"
html += "</tr>"
html += "</table>"
return {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),"KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":desc,"KEY_TRACKLIST":trackshtml,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}
return {"KEY_ARTISTNAME":keys["artist"],"KEY_ENC_ARTISTNAME":urllib.parse.quote(keys["artist"]),"KEY_IMAGEURL":imgurl, "KEY_DESCRIPTION":desc,"KEY_TRACKLIST":html,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}

View File

@ -12,7 +12,7 @@ def replacedict(keys,dbport):
if db_data["inconsistent"]:
html += "<tr>"
html += "<td>The current database wasn't built with all current rules in effect. Any problem below might be a false alarm and fixing it could create redundant rules.</td>"
html += """<td class='button important' onclick="fullrebuild()">Rebuild the database</td>"""
html += """<td class='button important' onclick="fullrebuild()"><div>Rebuild the database</div></td>"""
html += "</tr>"
i += 1
for d in db_data["duplicates"]:
@ -20,8 +20,8 @@ def replacedict(keys,dbport):
html += "<td>'" + artistLink(d[0]) + "'"
html += " is a possible duplicate of "
html += "'" + artistLink(d[1]) + "'</td>"
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + d[0] + """','""" + d[1] + """')">""" + d[1] + """ is correct</td>"""
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + d[1] + """','""" + d[0] + """')">""" + d[0] + """ is correct</td>"""
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + d[0] + """','""" + d[1] + """')"><div>""" + d[1] + """ is correct</div></td>"""
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + d[1] + """','""" + d[0] + """')"><div>""" + d[0] + """ is correct</div></td>"""
html += "</tr>"
i += 1
for c in db_data["combined"]:
@ -30,13 +30,13 @@ def replacedict(keys,dbport):
for a in c[1]:
html += "'" + artistLink(a) + "' "
html += "</td>"
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + c[0] + """','""" + "".join(c[1]) + """')">Fix it</td>"""
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + c[0] + """','""" + "".join(c[1]) + """')"><div>Fix it</div></td>"""
html += "</tr>"
i += 1
for n in db_data["newartists"]:
html += "<tr>"
html += "<td>Is '" + n[0] + "' in '" + artistLink(n[1]) + "' an artist?</td>"
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + n[1] + """','""" + "".join(n[2] + [n[0]]) + """')">Yes</td>"""
html += """<td class='button' onclick="newrule(this,'replaceartist','""" + n[1] + """','""" + "".join(n[2] + [n[0]]) + """')"><div>Yes</div></td>"""
html += "</tr>"
i += 1

View File

@ -51,12 +51,15 @@ table.top_info td.text .stats {
text-align:right;
color:grey;
}
a {
cursor:pointer;
}
table.list {
border-collapse:collapse;
}
table.list tr {
table.list tr td {
border-bottom:2px solid;
border-color:rgba(0,0,0,0)
@ -66,7 +69,7 @@ table tr:nth-child(even) {
background-color:#37373B;
}
table tr:nth-child(5n) {
table tr:nth-child(5n) td {
border-color:rgba(120,120,120,0.2);
}
@ -83,7 +86,9 @@ table td.amount {
text-align:right;
}
table td.bar {
width:300px;
width:500px;
background-color:#333337;
border-color:rgba(0,0,0,0)!important;
}
table td.bar div {
background-color:beige;
@ -97,14 +102,17 @@ table tr:hover td.bar div {
table td.button {
width:200px;
background-color:yellow;
color:#333337;
padding:4px;
border-radius:4px;
cursor:pointer;
}
td.button.important {
table td.button div {
background-color:yellow;
color:#333337;
padding:3px;
border-radius:4px;
}
td.button.important div {
background-color:red;
color:white;
}

View File

@ -3,7 +3,7 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo, getTimeDesc
from utilities import getArtistInfo, getTimeDesc, artistLink
#hand down the since and from arguments
@ -17,8 +17,8 @@ def replacedict(keys,dbport):
limitstring = ""
if keys.get("artist") is not None:
limitstring += "by <a href='/artist?artist=" + urllib.parse.quote(keys.get("artist")) + "'>" + keys.get("artist") + "</a> "
#limitstring += "by <a href='/artist?artist=" + urllib.parse.quote(keys.get("artist")) + "'>" + keys.get("artist") + "</a> "
limitstring += "by " + artistLink(keys.get("artist"))
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
db_data = json.loads(response.read())
@ -30,10 +30,11 @@ def replacedict(keys,dbport):
timestring = getTimeDesc(s["time"])
html += timestring
html += "</td><td class='artists'>"
artisthtml = ""
for a in s["artists"]:
artisthtml += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
html += artisthtml[:-2]
html += ", ".join([artistLink(a) for a in s["artists"]])
#artisthtml = ""
#for a in s["artists"]:
# artisthtml += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
#html += artisthtml[:-2]
html += "</td><td class='title'>" + s["title"] + "</td></tr>"
html += "</table>"

View File

@ -3,7 +3,7 @@ import json
def replacedict(keys,dbport):
from utilities import getArtistInfo
from utilities import getArtistInfo, artistLink
#hand down the since and from arguments
extrakeys = urllib.parse.urlencode(keys,quote_via=urllib.parse.quote,safe="/")
@ -30,9 +30,10 @@ def replacedict(keys,dbport):
for e in charts:
html += "<tr>"
html += "<td class='rank'>#" + str(i) + "</td><td class='artist'>"
html += "<a href=/artist?artist=" + urllib.parse.quote(e["artist"]) + ">" + e["artist"] + "</a>"
#html += "<a href=/artist?artist=" + urllib.parse.quote(e["artist"]) + ">" + e["artist"] + "</a>"
html += artistLink(e["artist"])
html += "</td><td class='amount'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td>"
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'><div style='width:" + str(int(e["scrobbles"]/maxbar * 100)) + "%;'></div></a></td>"
html += "<td class='bar'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'><div style='width:" + str(e["scrobbles"]/maxbar * 100) + "%;'></div></a></td>"
html += "</tr>"
i += 1
html += "</table>"