mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Cleanup and some fixing
This commit is contained in:
parent
91d4f79aa4
commit
4c2266b9d6
55
database.py
55
database.py
@ -4,7 +4,6 @@ import waitress
|
|||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
DATABASE = []
|
|
||||||
|
|
||||||
SCROBBLES = [] # Format: tuple(track_ref,timestamp,saved)
|
SCROBBLES = [] # Format: tuple(track_ref,timestamp,saved)
|
||||||
ARTISTS = [] # Format: artist
|
ARTISTS = [] # Format: artist
|
||||||
@ -25,7 +24,6 @@ TRACKS = [] # Format: tuple(frozenset(artist_ref,...),title)
|
|||||||
# by object
|
# by object
|
||||||
|
|
||||||
def getScrobbleObject(o):
|
def getScrobbleObject(o):
|
||||||
#return {"artists":getTrackObject(SCROBBLES[o][0])["artists"],"title":getTrackObject(SCROBBLES[o][0])["title"],"time":SCROBBLES[o][1],"saved":SCROBBLES[o][2]}
|
|
||||||
track = getTrackObject(TRACKS[o[0]])
|
track = getTrackObject(TRACKS[o[0]])
|
||||||
return {"artists":track["artists"],"title":track["title"],"time":o[1]}
|
return {"artists":track["artists"],"title":track["title"],"time":o[1]}
|
||||||
|
|
||||||
@ -76,37 +74,13 @@ def getTrackID(artists,title):
|
|||||||
def get_scrobbles():
|
def get_scrobbles():
|
||||||
keys = request.query
|
keys = request.query
|
||||||
r = db_query(artist=keys.get("artist"))
|
r = db_query(artist=keys.get("artist"))
|
||||||
#print(r)
|
|
||||||
response.content_type = "application/json; charset=UTF-8"
|
|
||||||
#response.charset = 'UTF-8'
|
|
||||||
return {"list":r} ##json can't be a list apparently???
|
|
||||||
|
|
||||||
#r = db_query(artist=keys.get("artist"))
|
return {"list":r} ##json can't be a list apparently???
|
||||||
#text = ""
|
|
||||||
#for e in r:
|
|
||||||
# entry = ""
|
|
||||||
# for a in e["artists"]:
|
|
||||||
# entry += a + "/"
|
|
||||||
# entry += " " + e["title"] + "\n"
|
|
||||||
# text += entry
|
|
||||||
#return text
|
|
||||||
|
|
||||||
@route("/tracks")
|
@route("/tracks")
|
||||||
def get_tracks():
|
def get_tracks():
|
||||||
artist = request.query.get("artist")
|
artist = request.query.get("artist")
|
||||||
|
|
||||||
global TRACKS
|
|
||||||
|
|
||||||
|
|
||||||
# turn the tupel of frozensets into a jsonable object
|
|
||||||
#tracklist = [{"artists":list(a[0]),"title":a[1]} for a in TRACKS]
|
|
||||||
|
|
||||||
#ls = [t for t in tracklist if (artist in t["artists"]) or (artist==None)]
|
|
||||||
|
|
||||||
|
|
||||||
### WHICH ONE IS FASTER
|
|
||||||
import time
|
|
||||||
|
|
||||||
# Option 1
|
# Option 1
|
||||||
ls = [getTrackObject(t) for t in TRACKS if (artist in t[0]) or (artist==None)]
|
ls = [getTrackObject(t) for t in TRACKS if (artist in t[0]) or (artist==None)]
|
||||||
|
|
||||||
@ -118,8 +92,7 @@ def get_tracks():
|
|||||||
|
|
||||||
@route("/artists")
|
@route("/artists")
|
||||||
def get_artists():
|
def get_artists():
|
||||||
response.content_type = "application/json; charset=UTF-8"
|
|
||||||
#response.charset = "utf-8"
|
|
||||||
return {"list":ARTISTS}
|
return {"list":ARTISTS}
|
||||||
|
|
||||||
@route("/charts")
|
@route("/charts")
|
||||||
@ -144,10 +117,16 @@ def runserver(DATABASE_PORT):
|
|||||||
|
|
||||||
def build_db():
|
def build_db():
|
||||||
|
|
||||||
newscrobbles = [t for t in SCROBBLES if not t[2]]
|
global SCROBBLES
|
||||||
|
|
||||||
|
SCROBBLESNEW = []
|
||||||
|
for t in SCROBBLES:
|
||||||
|
if not t[2]:
|
||||||
|
SCROBBLESNEW.append(t)
|
||||||
|
|
||||||
|
SCROBBLES = SCROBBLESNEW
|
||||||
|
|
||||||
for f in os.listdir("logs/"):
|
for f in os.listdir("logs/"):
|
||||||
#print(f)
|
|
||||||
|
|
||||||
if not (".csv" in f):
|
if not (".csv" in f):
|
||||||
continue
|
continue
|
||||||
@ -157,8 +136,6 @@ def build_db():
|
|||||||
|
|
||||||
l = l.replace("\n","")
|
l = l.replace("\n","")
|
||||||
data = l.split(",")
|
data = l.split(",")
|
||||||
#print(l)
|
|
||||||
|
|
||||||
|
|
||||||
## saving album in the scrobbles is supported, but for now we don't use it. It shouldn't be a defining part of the track (same song from Album or EP), but derived information
|
## saving album in the scrobbles is supported, but for now we don't use it. It shouldn't be a defining part of the track (same song from Album or EP), but derived information
|
||||||
artists = data[1].split("/")
|
artists = data[1].split("/")
|
||||||
@ -167,8 +144,6 @@ def build_db():
|
|||||||
time = int(data[0])
|
time = int(data[0])
|
||||||
|
|
||||||
readScrobble(artists,title,time)
|
readScrobble(artists,title,time)
|
||||||
|
|
||||||
#DATABASE.append({"artists":artists,"title":title,"time":time,"saved":True})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -271,9 +246,11 @@ def reload():
|
|||||||
|
|
||||||
# Saves all cached entries to disk
|
# Saves all cached entries to disk
|
||||||
def flush():
|
def flush():
|
||||||
for t in DATABASE:
|
for s in SCROBBLES:
|
||||||
if not t["saved"]:
|
if not s[2]:
|
||||||
|
|
||||||
|
t = getScrobbleObject(s)
|
||||||
|
|
||||||
artistss = "/".join(t["artists"])
|
artistss = "/".join(t["artists"])
|
||||||
timestamp = datetime.date.fromtimestamp(t["time"])
|
timestamp = datetime.date.fromtimestamp(t["time"])
|
||||||
|
|
||||||
@ -284,7 +261,7 @@ def flush():
|
|||||||
monthfile.write("\n")
|
monthfile.write("\n")
|
||||||
monthfile.close()
|
monthfile.close()
|
||||||
|
|
||||||
t["saved"] = True
|
t[2] = True
|
||||||
|
|
||||||
|
|
||||||
# Queries the database
|
# Queries the database
|
||||||
|
Loading…
Reference in New Issue
Block a user