From 74dc54862ef346c310239f691be3871e8c3e4cdd Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 1 Dec 2020 20:32:29 +0100 Subject: [PATCH] Added progress bar to database build, GH-54 --- maloja/database.py | 7 +++++++ maloja/malojatime.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/maloja/database.py b/maloja/database.py index 2741e26..25098ce 100644 --- a/maloja/database.py +++ b/maloja/database.py @@ -18,6 +18,7 @@ from doreah import tsv from doreah import settings from doreah.caching import Cache, DeepCache from doreah.auth import authenticated_api, authenticated_api_with_alternate +from doreah.io import ProgressBar try: from doreah.persistence import DiskDict except: pass @@ -767,6 +768,9 @@ def build_db(): # parse files db = tsv.parse_all(datadir("scrobbles"),"int","string","string",comments=False) + scrobblenum = len(db) + log(f"Found {scrobblenum} scrobbles...") + pbar = ProgressBar(max=scrobblenum,prefix="Loading scrobbles") #db = parseAllTSV("scrobbles","int","string","string",escape=False) for sc in db: artists = sc[1].split("␟") @@ -774,7 +778,10 @@ def build_db(): time = sc[0] readScrobble(artists,title,time) + pbar.progress() + pbar.done() + log("Database loaded, optimizing...") # optimize database SCROBBLES.sort(key = lambda tup: tup[1]) diff --git a/maloja/malojatime.py b/maloja/malojatime.py index 43379c6..9e18f5f 100644 --- a/maloja/malojatime.py +++ b/maloja/malojatime.py @@ -590,10 +590,10 @@ def delimit_desc_p(d): def delimit_desc(step="month",stepn=1,trail=1): txt = "" - if stepn is not 1: txt += str(stepn) + "-" + if stepn != 1: txt += str(stepn) + "-" txt += {"year":"Yearly","month":"Monthly","week":"Weekly","day":"Daily"}[step.lower()] if trail is math.inf: txt += " Cumulative" - elif trail is not 1: txt += " Trailing" #we don't need all the info in the title + elif trail != 1: txt += " Trailing" #we don't need all the info in the title return txt