mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Basic artist overview webpage
This commit is contained in:
2
website/.gitignore
vendored
Normal file
2
website/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
__pycache__
|
||||
apikey
|
||||
29
website/artist.html
Normal file
29
website/artist.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Maloja</title>
|
||||
<link rel="stylesheet" href="maloja.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table class="top_info">
|
||||
<tr>
|
||||
<td class="image">
|
||||
<img src="KEY_IMAGEURL" />
|
||||
</td>
|
||||
<td class="text">
|
||||
<h1>KEY_ARTISTNAME</h1>
|
||||
<p class="stats">2342 Scrobbles / 23th all time / 12th this month</p>
|
||||
|
||||
KEY_DESCRIPTION
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Tracks</h2>
|
||||
KEY_TRACKLIST
|
||||
|
||||
</body>
|
||||
</html>
|
||||
48
website/artist.py
Normal file
48
website/artist.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import urllib
|
||||
import json
|
||||
|
||||
|
||||
|
||||
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 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"
|
||||
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"]))
|
||||
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 += "</td><td>" + e["title"] + "</td>"
|
||||
tracks.append(html)
|
||||
|
||||
trackshtml = "<table>"
|
||||
for t in tracks:
|
||||
trackshtml += "<tr>"
|
||||
trackshtml += t
|
||||
trackshtml += "</tr>"
|
||||
trackshtml += "</table>"
|
||||
|
||||
|
||||
return {"KEY_ARTISTNAME":keys["artist"],"KEY_IMAGEURL":imgurl,"KEY_DESCRIPTION":desc,"KEY_TRACKLIST":trackshtml}
|
||||
@@ -1,8 +1,30 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Ubuntu');
|
||||
|
||||
body {
|
||||
background-color:#111114;
|
||||
background-color:#333337;
|
||||
color:beige;
|
||||
font-family:"Ubuntu";
|
||||
padding:15px;
|
||||
}
|
||||
|
||||
a {
|
||||
color:lightgray;
|
||||
text-decoration:none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
table.top_info td.image {
|
||||
padding:20px;
|
||||
}
|
||||
|
||||
table.top_info td.text {
|
||||
vertical-align: top;
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
table.top_info td.text p.stats {
|
||||
color:grey;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user