From 8ebd27ab76ad2dcaf1dfef0cc171900fa20d5ee5 Mon Sep 17 00:00:00 2001 From: krateng Date: Mon, 24 May 2021 13:49:58 +0200 Subject: [PATCH] Added some output for errors in import and start --- maloja/__pkginfo__.py | 2 +- maloja/proccontrol/control.py | 2 +- maloja/proccontrol/tasks/__init__.py | 9 +-- maloja/proccontrol/tasks/lastfmconverter.py | 76 +++++++++++++-------- maloja/server.py | 9 ++- 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index f5fe97a..66ca9e3 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -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", diff --git a/maloja/proccontrol/control.py b/maloja/proccontrol/control.py index 12c4342..8bea450 100644 --- a/maloja/proccontrol/control.py +++ b/maloja/proccontrol/control.py @@ -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")) diff --git a/maloja/proccontrol/tasks/__init__.py b/maloja/proccontrol/tasks/__init__.py index 37dd85a..82c00cd 100644 --- a/maloja/proccontrol/tasks/__init__.py +++ b/maloja/proccontrol/tasks/__init__.py @@ -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 diff --git a/maloja/proccontrol/tasks/lastfmconverter.py b/maloja/proccontrol/tasks/lastfmconverter.py index c3dc93d..e75d1f2 100644 --- a/maloja/proccontrol/tasks/lastfmconverter.py +++ b/maloja/proccontrol/tasks/lastfmconverter.py @@ -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) diff --git a/maloja/server.py b/maloja/server.py index b046ce9..549ea8e 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -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