[boardgames] Check if scrobble exists first
This commit is contained in:
@ -15,7 +15,10 @@ def process_scrobbles_from_imap() -> list[Scrobble]:
|
|||||||
scrobbles_created: list[Scrobble] = []
|
scrobbles_created: list[Scrobble] = []
|
||||||
|
|
||||||
active_profiles = UserProfile.objects.filter(imap_auto_import=True)
|
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:
|
for profile in active_profiles:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Importing scrobbles from IMAP for user",
|
"Importing scrobbles from IMAP for user",
|
||||||
@ -75,17 +78,21 @@ def process_scrobbles_from_imap() -> list[Scrobble]:
|
|||||||
file_data.decode("utf-8")
|
file_data.decode("utf-8")
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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:
|
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
|
continue
|
||||||
|
|
||||||
scrobble = email_scrobble_board_game(
|
scrobbles_created = email_scrobble_board_game(
|
||||||
parsed_json, profile.user_id
|
parsed_json, profile.user_id
|
||||||
)
|
)
|
||||||
if scrobble:
|
|
||||||
scrobbles_created.append(scrobble)
|
|
||||||
|
|
||||||
mail.logout()
|
mail.logout()
|
||||||
|
|
||||||
|
|||||||
@ -1092,7 +1092,6 @@ class Scrobble(TimeStampedModel):
|
|||||||
)
|
)
|
||||||
source = scrobble_data.get("source", "Vrobbler")
|
source = scrobble_data.get("source", "Vrobbler")
|
||||||
mtype = media.__class__.__name__
|
mtype = media.__class__.__name__
|
||||||
mopidy_status = scrobble_data.get("mopidy_status", None)
|
|
||||||
|
|
||||||
# GeoLocations are a special case scrobble
|
# GeoLocations are a special case scrobble
|
||||||
if mtype == cls.MediaType.GEO_LOCATION:
|
if mtype == cls.MediaType.GEO_LOCATION:
|
||||||
|
|||||||
@ -445,7 +445,15 @@ def email_scrobble_board_game(
|
|||||||
"log": log_data,
|
"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 = Scrobble.create_or_update(base_game, user_id, scrobble_dict)
|
||||||
scrobble.stop_timestamp = stop
|
scrobble.stop_timestamp = stop
|
||||||
scrobble.in_progress = False
|
scrobble.in_progress = False
|
||||||
|
|||||||
Reference in New Issue
Block a user