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:
@@ -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>
|
||||
|
||||
@@ -3,37 +3,57 @@ import json
|
||||
|
||||
|
||||
|
||||
def page(keys):
|
||||
|
||||
txt_keys = replace(keys)
|
||||
|
||||
|
||||
with open("website/artist.html","r") as htmlfile:
|
||||
html = htmlfile.read()
|
||||
|
||||
#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
|
||||
|
||||
def replacedict(keys,dbport):
|
||||
|
||||
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}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user