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:
parent
1643eafc71
commit
6be0dfd25b
18
cleanup.py
18
cleanup.py
@ -49,6 +49,13 @@ class CleanerAgent:
|
|||||||
if re.match(r"(.*) \(" + d + " (.*)\)",a) is not None:
|
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))
|
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):
|
for d in (self.delimiters_feat + self.delimiters):
|
||||||
if ((" " + d + " ") in a):
|
if ((" " + d + " ") in a):
|
||||||
ls = []
|
ls = []
|
||||||
@ -56,12 +63,7 @@ class CleanerAgent:
|
|||||||
ls += self.parseArtists(i)
|
ls += self.parseArtists(i)
|
||||||
return ls
|
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" \(as made famous by .*?\)","",t)
|
||||||
t = re.sub(r" \(originally by .*?\)","",t)
|
t = re.sub(r" \(originally by .*?\)","",t)
|
||||||
|
t = re.sub(r" \(.*?Remaster.*?\)","",t)
|
||||||
|
|
||||||
return t.strip()
|
return t.strip()
|
||||||
|
|
||||||
@ -132,6 +135,9 @@ class CollectorAgent:
|
|||||||
updatedArtists.append(self.getCredited(artist))
|
updatedArtists.append(self.getCredited(artist))
|
||||||
return list(set(updatedArtists))
|
return list(set(updatedArtists))
|
||||||
|
|
||||||
|
def getAllAssociated(self,artist):
|
||||||
|
return self.rules_include.get(artist,[])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
31
database.py
31
database.py
@ -121,7 +121,8 @@ def get_scrobbles():
|
|||||||
|
|
||||||
@route("/tracks")
|
@route("/tracks")
|
||||||
def get_tracks():
|
def get_tracks():
|
||||||
artist = request.query.get("artist")
|
keys = FormsDict.decode(request.query)
|
||||||
|
artist = keys.get("artist")
|
||||||
|
|
||||||
if artist is not None:
|
if artist is not None:
|
||||||
artistid = ARTISTS.index(artist)
|
artistid = ARTISTS.index(artist)
|
||||||
@ -297,20 +298,22 @@ def getNext(time,unit,step=1):
|
|||||||
elif unit == "week":
|
elif unit == "week":
|
||||||
return getNext(time,"day",step * 7)
|
return getNext(time,"day",step * 7)
|
||||||
|
|
||||||
|
@route("/artistinfo")
|
||||||
|
def artistInfo():
|
||||||
|
keys = FormsDict.decode(request.query)
|
||||||
|
artist = keys.get("artist")
|
||||||
|
|
||||||
#def addDate(date,inc):
|
charts = db_aggregate(by="ARTIST")
|
||||||
# newdate = [1,1,1]
|
scrobbles = len(db_query(artist=artist)) #we cant take the scrobble number from the charts because that includes all countas scrobbles
|
||||||
# newdate[0] = date[0] + inc[0]
|
try:
|
||||||
# newdate[1] = date[1] + inc[1]
|
c = [e for e in charts if e["artist"] == artist][0]
|
||||||
# newdate[2] = date[2] + inc[2]
|
others = sovereign.getAllAssociated(artist)
|
||||||
# while (newdate[1] > 12):
|
return {"scrobbles":scrobbles,"position":charts.index(c) + 1,"associated":others}
|
||||||
# newdate[1] -= 12
|
except:
|
||||||
# newdate[0] += 1
|
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one
|
||||||
# while (newdate[1] < 1):
|
artist = sovereign.getCredited(artist)
|
||||||
# newdate[1] += 12
|
c = [e for e in charts if e["artist"] == artist][0]
|
||||||
# newdate[0] -= 1
|
return {"replace":artist,"scrobbles":scrobbles,"position":charts.index(c) + 1}
|
||||||
#
|
|
||||||
# return newdate
|
|
||||||
|
|
||||||
def isPast(date,limit):
|
def isPast(date,limit):
|
||||||
if not date[0] == limit[0]:
|
if not date[0] == limit[0]:
|
||||||
|
10
server.py
10
server.py
@ -81,8 +81,16 @@ def static(name):
|
|||||||
|
|
||||||
@route("/<name>")
|
@route("/<name>")
|
||||||
def static_html(name):
|
def static_html(name):
|
||||||
|
keys = FormsDict.decode(request.query)
|
||||||
if os.path.exists("website/" + name + ".py"):
|
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="")
|
return static_file("website/" + name + ".html",root="")
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@
|
|||||||
<img src="KEY_IMAGEURL" />
|
<img src="KEY_IMAGEURL" />
|
||||||
</td>
|
</td>
|
||||||
<td class="text">
|
<td class="text">
|
||||||
<h1>KEY_ARTISTNAME</h1>
|
<h1>KEY_ARTISTNAME</h1> <span class="stats">KEY_POSITION</span><br/>
|
||||||
<p class="stats">2342 Scrobbles / 23th all time / 12th this month</p>
|
<span>KEY_ASSOCIATED</span>
|
||||||
|
<p class="stats">KEY_SCROBBLES Scrobbles</p>
|
||||||
|
|
||||||
KEY_DESCRIPTION
|
KEY_DESCRIPTION
|
||||||
</td>
|
</td>
|
||||||
|
@ -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:
|
with open("website/apikey","r") as keyfile:
|
||||||
apikey = keyfile.read().replace("\n","")
|
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)
|
response = urllib.request.urlopen(url)
|
||||||
lastfm_data = json.loads(response.read())
|
lastfm_data = json.loads(response.read())
|
||||||
imgurl = lastfm_data["artist"]["image"][2]["#text"]
|
imgurl = lastfm_data["artist"]["image"][2]["#text"]
|
||||||
desc = lastfm_data["artist"]["bio"]["summary"]
|
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())
|
db_data = json.loads(response.read())
|
||||||
tracks = []
|
tracks = []
|
||||||
for e in db_data["list"]:
|
for e in db_data["list"]:
|
||||||
html = "<td>"
|
html = "<td>"
|
||||||
for a in e["artists"]:
|
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>"
|
html += "</td><td>" + e["title"] + "</td>"
|
||||||
tracks.append(html)
|
tracks.append(html)
|
||||||
|
|
||||||
@ -45,4 +65,4 @@ def replace(keys):
|
|||||||
trackshtml += "</table>"
|
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}
|
||||||
|
@ -18,6 +18,8 @@ a:hover {
|
|||||||
|
|
||||||
table.top_info td.image {
|
table.top_info td.image {
|
||||||
padding:20px;
|
padding:20px;
|
||||||
|
padding-left:0px;
|
||||||
|
padding-top:0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.top_info td.text {
|
table.top_info td.text {
|
||||||
@ -25,6 +27,11 @@ table.top_info td.text {
|
|||||||
padding-left: 30px;
|
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;
|
color:grey;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user