Ver Fonte

Fix appending count to TSV log

Colin Powell há 2 anos atrás
pai
commit
31907ed1b2
2 ficheiros alterados com 6 adições e 6 exclusões
  1. 5 3
      vrobbler/apps/scrobbles/models.py
  2. 1 3
      vrobbler/apps/scrobbles/tsv.py

+ 5 - 3
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"

+ 1 - 3
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: