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

Added some output for errors in import and start

This commit is contained in:
krateng 2021-05-24 13:49:58 +02:00
parent 5455abd0d1
commit 8ebd27ab76
5 changed files with 60 additions and 38 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@dev.krateng.ch",
"github": "krateng"
}
version = 2,12,7
version = 2,12,8
versionstr = ".".join(str(n) for n in version)
links = {
"pypi":"malojaserver",

View File

@ -40,7 +40,7 @@ def start():
port = settings.get_settings("WEB_PORT")
print("Visit your server address (Port " + str(port) + ") to see your web interface. Visit /setup to get started.")
print("Visit your server address (Port " + str(port) + ") to see your web interface. Visit /admin_setup to get started.")
print("If you're installing this on your local machine, these links should get you there:")
print("\t" + col["blue"]("http://localhost:" + str(port)))
print("\t" + col["blue"]("http://localhost:" + str(port) + "/admin_setup"))

View File

@ -1,5 +1,5 @@
import os
from doreah.io import ask
from doreah.io import ask,col
from ...globalconf import data_dir
@ -17,9 +17,10 @@ def loadlastfm(filename):
print("Please wait...")
from .lastfmconverter import convert
convert(filename,data_dir['scrobbles']("lastfmimport.tsv"))
print("Successfully imported your Last.FM scrobbles!")
imported,failed = convert(filename,data_dir['scrobbles']("lastfmimport.tsv"))
print("Successfully imported",imported,"Last.FM scrobbles!")
if failed > 0:
print(col['red'](str(failed) + " Errors!"))
def backuphere():
from .backup import backup

View File

@ -1,5 +1,6 @@
import os, datetime, re
from ...cleanup import *
from doreah.io import col
#from ...utilities import *
@ -17,46 +18,61 @@ def convert(input,output):
stamps = [99999999999999]
success = 0
failed = 0
for l in log:
l = l.replace("\n","")
data = l.split(",")
try:
artist,album,title,time = l.split(",")
except KeyboardInterrupt:
raise
except:
print(col['red']("Line '" + l + "' does not look like a valid entry. Scrobble not imported."))
failed += 1
continue
artist = data[0]
album = data[1]
title = data[2]
time = data[3]
try:
(artists,title) = c.fullclean(artist,title)
artistsstr = "".join(artists)
timeparts = time.split(" ")
(h,m) = timeparts[3].split(":")
months = {"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12}
timestamp = int(datetime.datetime(int(timeparts[2]),months[timeparts[1]],int(timeparts[0]),int(h),int(m)).timestamp())
(artists,title) = c.fullclean(artist,title)
artistsstr = "".join(artists)
timeparts = time.split(" ")
(h,m) = timeparts[3].split(":")
months = {"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12}
timestamp = int(datetime.datetime(int(timeparts[2]),months[timeparts[1]],int(timeparts[0]),int(h),int(m)).timestamp())
## We prevent double timestamps in the database creation, so we technically don't need them in the files
## however since the conversion from lastfm to maloja is a one-time thing, we should take any effort to make the file as good as possible
if (timestamp < stamps[-1]):
pass
elif (timestamp == stamps[-1]):
timestamp -= 1
else:
while(timestamp in stamps):
## We prevent double timestamps in the database creation, so we technically don't need them in the files
## however since the conversion from lastfm to maloja is a one-time thing, we should take any effort to make
## the file as good as possible
if (timestamp < stamps[-1]):
pass
elif (timestamp == stamps[-1]):
timestamp -= 1
else:
while(timestamp in stamps):
timestamp -= 1
if (timestamp < stamps[-1]):
stamps.append(timestamp)
else:
stamps.insert(0,timestamp)
if (timestamp < stamps[-1]):
stamps.append(timestamp)
else:
stamps.insert(0,timestamp)
except KeyboardInterrupt:
raise
except:
print(col['red']("Line '" + l + "' could not be parsed. Scrobble not imported."))
failed += 1
continue
entry = "\t".join([str(timestamp),artistsstr,title,album])
outputlog.write(entry)
outputlog.write("\n")
success += 1
if success % 100 == 0:
print("Imported " + str(success) + " scrobbles...")
return (success,failed)

View File

@ -273,5 +273,10 @@ setproctitle.setproctitle("Maloja")
database.start_db()
log("Starting up Maloja server...")
#run(webserver, host=HOST, port=MAIN_PORT, server='waitress')
waitress.serve(webserver, host=HOST, port=MAIN_PORT, threads=THREADS)
try:
#run(webserver, host=HOST, port=MAIN_PORT, server='waitress')
waitress.serve(webserver, host=HOST, port=MAIN_PORT, threads=THREADS)
except OSError:
log("Error. Is another Maloja process already running?")
raise