From 31907ed1b2bd9e8792051d459b75e92cbe2aa971 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Sun, 12 Feb 2023 17:03:30 -0500 Subject: [PATCH] Fix appending count to TSV log --- vrobbler/apps/scrobbles/models.py | 8 +++++--- vrobbler/apps/scrobbles/tsv.py | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 3608913..300e023 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -56,10 +56,12 @@ class AudioScrobblerTSVImport(TimeStampedModel): self.tsv_file.path, user_tz=tz ) if scrobbles: - self.process_log = f"Created {len(scrobbles)} scrobbles" - for scrobble in scrobbles: + for count, scrobble in enumerate(scrobbles): scrobble_str = f"{scrobble.id}\t{scrobble.timestamp}\t{scrobble.track.title}" - self.process_log += f"\n{scrobble_str}" + log_line = f"{scrobble_str}" + if count > 0: + log_line = "\n" + log_line + self.process_log += log_line self.process_count = len(scrobbles) else: self.process_log = f"Created no new scrobbles" diff --git a/vrobbler/apps/scrobbles/tsv.py b/vrobbler/apps/scrobbles/tsv.py index c998d65..eaf4c70 100644 --- a/vrobbler/apps/scrobbles/tsv.py +++ b/vrobbler/apps/scrobbles/tsv.py @@ -124,9 +124,7 @@ def undo_audioscrobbler_tsv_import(process_log, dryrun=True): logger.warning("No lines in process log found to undo") return - for line_num, line in enumerate(process_log.split('\n')): - if line_num == 0: - continue + for line in process_log.split('\n'): scrobble_id = line.split("\t")[0] scrobble = Scrobble.objects.filter(id=scrobble_id).first() if not scrobble: