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

50 lines
1.7 KiB
Python
Raw Normal View History

2018-12-16 19:52:13 +03:00
import urllib
import json
2018-12-17 01:56:30 +03:00
def replacedict(keys,dbport):
2018-12-17 17:10:10 +03:00
from utilities import getArtistInfo
2018-12-16 19:52:13 +03:00
2018-12-17 01:56:30 +03:00
2018-12-17 17:10:10 +03:00
info = getArtistInfo(keys["artist"])
imgurl = info.get("image")
desc = info.get("info")
2018-12-16 19:52:13 +03:00
2018-12-17 01:56:30 +03:00
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"])
2018-12-17 18:33:26 +03:00
2018-12-17 01:56:30 +03:00
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"]))
2018-12-16 19:52:13 +03:00
db_data = json.loads(response.read())
tracks = []
for e in db_data["list"]:
html = "<td class='artists'>"
2018-12-16 19:52:13 +03:00
for a in e["artists"]:
2018-12-17 01:56:30 +03:00
html += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
html = html[:-2]
html += "</td><td class='title'>" + e["title"] + "</td>"
2018-12-16 19:52:13 +03:00
tracks.append(html)
trackshtml = "<table>"
for t in tracks:
trackshtml += "<tr>"
trackshtml += t
trackshtml += "</tr>"
trackshtml += "</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}