mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added script to fix existing database with new rules
This commit is contained in:
parent
3591f437ed
commit
b361e25503
@ -22,7 +22,7 @@ I like to name my projects after regions in Grisons, Switzerland. Don't waste yo
|
||||
|
||||
## Current status
|
||||
|
||||
Deep in development. I just uploaded Maloja here in case I die tomorrow. It can accept scrobbles and return some basic stats in JSON format so far.
|
||||
Deep in development. I just uploaded Maloja here in case I die tomorrow. It can accept scrobbles and return a few webpages (/artist, /scrobbles, /topartists).
|
||||
|
||||
## How to install
|
||||
|
||||
|
@ -76,7 +76,6 @@ class CleanerAgent:
|
||||
return [a.strip()]
|
||||
|
||||
def parseTitle(self,t):
|
||||
|
||||
if t.strip() in self.rules_replacetitle:
|
||||
return self.rules_replacetitle[t.strip()]
|
||||
|
||||
|
@ -116,7 +116,7 @@ def test_server():
|
||||
|
||||
@dbserver.route("/scrobbles")
|
||||
def get_scrobbles():
|
||||
keys = request.query
|
||||
keys = FormsDict.decode(request.query)
|
||||
r = db_query(artist=keys.get("artist"),track=keys.get("track"),since=keys.get("since"),to=keys.get("to"))
|
||||
r.reverse()
|
||||
|
||||
|
32
fixexisting.py
Normal file
32
fixexisting.py
Normal file
@ -0,0 +1,32 @@
|
||||
import os
|
||||
import re
|
||||
from cleanup import CleanerAgent
|
||||
|
||||
wendigo = CleanerAgent()
|
||||
|
||||
exp = r"([0-9]*)(\t+)([^\t]+?)(\t+)([^\t]+)(\t*)([^\t]*)\n"
|
||||
|
||||
for fn in os.listdir("scrobbles/"):
|
||||
if fn.endswith(".tsv"):
|
||||
f = open("scrobbles/" + fn)
|
||||
fnew = open("scrobbles/" + fn + "_new","w")
|
||||
for l in f:
|
||||
|
||||
a,t = re.sub(exp,r"\3",l), re.sub(exp,r"\5",l)
|
||||
r1,r2,r3 = re.sub(exp,r"\1\2",l),re.sub(exp,r"\4",l),re.sub(exp,r"\6\7",l)
|
||||
|
||||
a = a.replace("␟",";")
|
||||
|
||||
(al,t) = wendigo.fullclean(a,t)
|
||||
a = "␟".join(al)
|
||||
fnew.write(r1 + a + r2 + t + r3 + "\n")
|
||||
#print("Artists: " + a)
|
||||
#print("Title: " + t)
|
||||
#print("1: " + r1)
|
||||
#print("2: " + r2)
|
||||
#print("3: " + r3)
|
||||
|
||||
f.close()
|
||||
fnew.close()
|
||||
|
||||
os.rename("scrobbles/" + fn + "_new","scrobbles/" + fn)
|
@ -16,7 +16,7 @@
|
||||
<td class="text">
|
||||
<h1>KEY_ARTISTNAME</h1> <span class="stats">KEY_POSITION</span><br/>
|
||||
<span>KEY_ASSOCIATED</span>
|
||||
<p class="stats">KEY_SCROBBLES Scrobbles</p>
|
||||
<p class="stats"><a href="/scrobbles?artist=KEY_ENC_ARTISTNAME">KEY_SCROBBLES Scrobbles</a></p>
|
||||
|
||||
<p>KEY_DESCRIPTION</p>
|
||||
</td>
|
||||
|
@ -31,11 +31,11 @@ def replacedict(keys,dbport):
|
||||
db_data = json.loads(response.read())
|
||||
tracks = []
|
||||
for e in db_data["list"]:
|
||||
html = "<td>"
|
||||
html = "<td class='artists'>"
|
||||
for a in e["artists"]:
|
||||
html += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
|
||||
html = html[:-2]
|
||||
html += "</td><td>" + e["title"] + "</td>"
|
||||
html += "</td><td class='title'>" + e["title"] + "</td>"
|
||||
tracks.append(html)
|
||||
|
||||
trackshtml = "<table>"
|
||||
@ -46,4 +46,4 @@ def replacedict(keys,dbport):
|
||||
trackshtml += "</table>"
|
||||
|
||||
|
||||
return {"KEY_ARTISTNAME":keys["artist"],"KEY_IMAGEURL":imgurl,"KEY_DESCRIPTION":desc,"KEY_TRACKLIST":trackshtml,"KEY_SCROBBLES":scrobbles,"KEY_POSITION":pos,"KEY_ASSOCIATED":includestr}
|
||||
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}
|
||||
|
@ -43,3 +43,15 @@ table.top_info td.text h1 {
|
||||
table.top_info td.text .stats {
|
||||
color:grey;
|
||||
}
|
||||
|
||||
table tr:nth-child(even) {
|
||||
background-color:#37373B;
|
||||
}
|
||||
|
||||
table td.time {
|
||||
width:200px;
|
||||
color:lightgray;
|
||||
}
|
||||
table td.artists,td.artist,td.title,td.amount {
|
||||
width:300px;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ def replacedict(keys,dbport):
|
||||
|
||||
limitstring = ""
|
||||
if keys.get("artist") is not None:
|
||||
limitstring += "by " + keys.get("artist") + " "
|
||||
limitstring += "by <a href='/artist?artist=" + urllib.parse.quote(keys.get("artist")) + "'>" + keys.get("artist") + "</a> "
|
||||
|
||||
|
||||
response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + extrakeys)
|
||||
@ -26,15 +26,15 @@ def replacedict(keys,dbport):
|
||||
|
||||
html = "<table>"
|
||||
for s in scrobbles:
|
||||
html += "<tr><td>"
|
||||
html += "<tr><td class='time'>"
|
||||
timestring = getTimeDesc(s["time"])
|
||||
html += timestring
|
||||
html += "</td><td>"
|
||||
html += "</td><td class='artists'>"
|
||||
artisthtml = ""
|
||||
for a in s["artists"]:
|
||||
artisthtml += "<a href=/artist?artist=" + urllib.parse.quote(a) + ">" + a + "</a>, "
|
||||
html += artisthtml[:-2]
|
||||
html += "</td><td>" + s["title"] + "</td></tr>"
|
||||
html += "</td><td class='title'>" + s["title"] + "</td></tr>"
|
||||
html += "</table>"
|
||||
|
||||
return {"KEY_SCROBBLELIST":html,"KEY_SCROBBLES":str(len(scrobbles)),"KEY_IMAGEURL":imgurl,"KEY_LIMITS":limitstring}
|
||||
|
@ -27,9 +27,9 @@ def replacedict(keys,dbport):
|
||||
|
||||
html = "<table>"
|
||||
for e in charts:
|
||||
html += "<tr><td>"
|
||||
html += "<tr><td class='artist'>"
|
||||
html += "<a href=/artist?artist=" + urllib.parse.quote(e["artist"]) + ">" + e["artist"] + "</a>"
|
||||
html += "</td><td>" + str(e["scrobbles"]) + "</td></tr>"
|
||||
html += "</td><td class='amount'><a href='/scrobbles?artist=" + urllib.parse.quote(e["artist"]) + "&" + extrakeys + "'>" + str(e["scrobbles"]) + "</a></td></tr>"
|
||||
html += "</table>"
|
||||
|
||||
return {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_SCROBBLES":str(scrobbles),"KEY_ARTISTLIST":html}
|
||||
|
Loading…
Reference in New Issue
Block a user