diff --git a/vrobbler/apps/scrobbles/imap.py b/vrobbler/apps/scrobbles/imap.py index 5a18e73..7b68789 100644 --- a/vrobbler/apps/scrobbles/imap.py +++ b/vrobbler/apps/scrobbles/imap.py @@ -15,7 +15,10 @@ def process_scrobbles_from_imap() -> list[Scrobble]: scrobbles_created: list[Scrobble] = [] active_profiles = UserProfile.objects.filter(imap_auto_import=True) - logger.info("Starting import of scrobbles from IMAP", extra={"active_profiles": active_profiles}) + logger.info( + "Starting import of scrobbles from IMAP", + extra={"active_profiles": active_profiles}, + ) for profile in active_profiles: logger.info( "Importing scrobbles from IMAP for user", @@ -75,17 +78,21 @@ def process_scrobbles_from_imap() -> list[Scrobble]: file_data.decode("utf-8") ) except Exception as e: - logger.error("Failed to parse JSON file", extra={"filename": filename, "error": e}) + logger.error( + "Failed to parse JSON file", + extra={"filename": filename, "error": e}, + ) if not parsed_json: - logger.info("No JSON found in BG Stats file", extra={"filename": filename}) + logger.info( + "No JSON found in BG Stats file", + extra={"filename": filename}, + ) continue - scrobble = email_scrobble_board_game( + scrobbles_created = email_scrobble_board_game( parsed_json, profile.user_id ) - if scrobble: - scrobbles_created.append(scrobble) mail.logout() diff --git a/vrobbler/apps/scrobbles/models.py b/vrobbler/apps/scrobbles/models.py index 6b6d936..ec6f6d8 100644 --- a/vrobbler/apps/scrobbles/models.py +++ b/vrobbler/apps/scrobbles/models.py @@ -1092,7 +1092,6 @@ class Scrobble(TimeStampedModel): ) source = scrobble_data.get("source", "Vrobbler") mtype = media.__class__.__name__ - mopidy_status = scrobble_data.get("mopidy_status", None) # GeoLocations are a special case scrobble if mtype == cls.MediaType.GEO_LOCATION: diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index ddc8f0e..d3f0afe 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -445,7 +445,15 @@ def email_scrobble_board_game( "log": log_data, } - print(scrobble_dict) + scrobble = Scrobble.objects.filter( + board_game=base_game, user_id=user_id, timestamp=start + ).first() + if scrobble: + logger.info( + "Scrobble already exists, skipping", + extra={"scrobble_dict": scrobble_dict, "user_id": user_id}, + ) + continue scrobble = Scrobble.create_or_update(base_game, user_id, scrobble_dict) scrobble.stop_timestamp = stop scrobble.in_progress = False