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

Improvement and bugfixing

This commit is contained in:
Krateng 2018-12-16 23:56:30 +01:00
parent 1643eafc71
commit 6be0dfd25b
6 changed files with 87 additions and 42 deletions

View File

@ -49,6 +49,13 @@ class CleanerAgent:
if re.match(r"(.*) \(" + d + " (.*)\)",a) is not None:
return self.parseArtists(re.sub(r"(.*) \(" + d + " (.*)\)",r"\1",a)) + self.parseArtists(re.sub(r"(.*) \(" + d + " (.*)\)",r"\2",a))
for d in self.delimiters_formal:
if (d in a):
ls = []
for i in a.split(d):
ls += self.parseArtists(i)
return ls
for d in (self.delimiters_feat + self.delimiters):
if ((" " + d + " ") in a):
ls = []
@ -56,12 +63,7 @@ class CleanerAgent:
ls += self.parseArtists(i)
return ls
for d in self.delimiters_formal:
if (d in a):
ls = []
for i in a.split(d):
ls += self.parseArtists(i)
return ls
@ -76,6 +78,7 @@ class CleanerAgent:
t = re.sub(r" \(as made famous by .*?\)","",t)
t = re.sub(r" \(originally by .*?\)","",t)
t = re.sub(r" \(.*?Remaster.*?\)","",t)
return t.strip()
@ -132,6 +135,9 @@ class CollectorAgent:
updatedArtists.append(self.getCredited(artist))
return list(set(updatedArtists))
def getAllAssociated(self,artist):
return self.rules_include.get(artist,[])

View File

@ -121,7 +121,8 @@ def get_scrobbles():
@route("/tracks")
def get_tracks():
artist = request.query.get("artist")
keys = FormsDict.decode(request.query)
artist = keys.get("artist")
if artist is not None:
artistid = ARTISTS.index(artist)
@ -297,20 +298,22 @@ def getNext(time,unit,step=1):
elif unit == "week":
return getNext(time,"day",step * 7)
@route("/artistinfo")
def artistInfo():
keys = FormsDict.decode(request.query)
artist = keys.get("artist")
#def addDate(date,inc):
# newdate = [1,1,1]
# newdate[0] = date[0] + inc[0]
# newdate[1] = date[1] + inc[1]
# newdate[2] = date[2] + inc[2]
# while (newdate[1] > 12):
# newdate[1] -= 12
# newdate[0] += 1
# while (newdate[1] < 1):
# newdate[1] += 12
# newdate[0] -= 1
#
# return newdate
charts = db_aggregate(by="ARTIST")
scrobbles = len(db_query(artist=artist)) #we cant take the scrobble number from the charts because that includes all countas scrobbles
try:
c = [e for e in charts if e["artist"] == artist][0]
others = sovereign.getAllAssociated(artist)
return {"scrobbles":scrobbles,"position":charts.index(c) + 1,"associated":others}
except:
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one
artist = sovereign.getCredited(artist)
c = [e for e in charts if e["artist"] == artist][0]
return {"replace":artist,"scrobbles":scrobbles,"position":charts.index(c) + 1}
def isPast(date,limit):
if not date[0] == limit[0]:

View File

@ -81,8 +81,16 @@ def static(name):
@route("/<name>")
def static_html(name):
keys = FormsDict.decode(request.query)
if os.path.exists("website/" + name + ".py"):
return SourceFileLoader(name,"website/" + name + ".py").load_module().page(FormsDict.decode(request.query))
txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT)
with open("website/" + name + ".html") as htmlfile:
html = htmlfile.read()
for k in txt_keys:
html = html.replace(k,txt_keys[k])
return html
return static_file("website/" + name + ".html",root="")

View File

@ -14,8 +14,9 @@
<img src="KEY_IMAGEURL" />
</td>
<td class="text">
<h1>KEY_ARTISTNAME</h1>
<p class="stats">2342 Scrobbles / 23th all time / 12th this month</p>
<h1>KEY_ARTISTNAME</h1> <span class="stats">KEY_POSITION</span><br/>
<span>KEY_ASSOCIATED</span>
<p class="stats">KEY_SCROBBLES Scrobbles</p>
KEY_DESCRIPTION
</td>

View File

@ -3,37 +3,57 @@ import json
def page(keys):
#def page(keys):
#
# txt_keys = replace(keys)
#
#
# with open("website/artist.html","r") as htmlfile:
# html = htmlfile.read()
#
#
#
# for k in txt_keys:
# html = html.replace(k,txt_keys[k])
#
# return html
txt_keys = replace(keys)
def replacedict(keys,dbport):
with open("website/artist.html","r") as htmlfile:
html = htmlfile.read()
for k in txt_keys:
html = html.replace(k,txt_keys[k])
return html
def replace(keys):
with open("website/apikey","r") as keyfile:
apikey = keyfile.read().replace("\n","")
url = "https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + keys["artist"] + "&api_key=" + apikey + "&format=json"
url = "https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + urllib.parse.quote(keys["artist"]) + "&api_key=" + apikey + "&format=json"
response = urllib.request.urlopen(url)
lastfm_data = json.loads(response.read())
imgurl = lastfm_data["artist"]["image"][2]["#text"]
desc = lastfm_data["artist"]["bio"]["summary"]
response = urllib.request.urlopen("http://localhost:42010/db/tracks?artist=" + urllib.parse.quote(keys["artist"]))
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/artistinfo?artist=" + urllib.parse.quote(keys["artist"]))
db_data = json.loads(response.read())
scrobbles = str(db_data["scrobbles"])
pos = "#" + str(db_data["position"])
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 + ")"
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]
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>"
for a in e["artists"]:
html += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a> "
html += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
html = html[:-2]
html += "</td><td>" + e["title"] + "</td>"
tracks.append(html)
@ -45,4 +65,4 @@ def replace(keys):
trackshtml += "</table>"
return {"KEY_ARTISTNAME":keys["artist"],"KEY_IMAGEURL":imgurl,"KEY_DESCRIPTION":desc,"KEY_TRACKLIST":trackshtml}
return {"KEY_ARTISTNAME":keys["artist"],"KEY_IMAGEURL":imgurl,"KEY_DESCRIPTION":desc,"KEY_TRACKLIST":trackshtml,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}

View File

@ -18,6 +18,8 @@ a:hover {
table.top_info td.image {
padding:20px;
padding-left:0px;
padding-top:0px;
}
table.top_info td.text {
@ -25,6 +27,11 @@ table.top_info td.text {
padding-left: 30px;
}
table.top_info td.text p.stats {
table.top_info td.text h1 {
display:inline;
padding-right:5px;
}
table.top_info td.text .stats {
color:grey;
}