From 4adaa3442c31d6efb7f9e4d1c35bffc5a08c51be Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 7 May 2025 20:52:37 +1000 Subject: [PATCH] fix --- foodie_utils.py | 5 +++++ foodie_weekly_thread.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/foodie_utils.py b/foodie_utils.py index 1a26df1..e9993fa 100644 --- a/foodie_utils.py +++ b/foodie_utils.py @@ -1224,12 +1224,17 @@ def save_post_to_recent(post_title, post_url, author_username, timestamp): """Save a post to recent_posts.json, maintaining a JSON array.""" try: recent_posts = load_json_file(RECENT_POSTS_FILE, expiration_hours=24) + # Check for duplicates before appending entry = { "title": post_title, "url": post_url, "author_username": author_username, "timestamp": timestamp } + key = (post_title, post_url, author_username) + if any((p["title"], p["url"], p["author_username"]) == key for p in recent_posts): + logging.debug(f"Skipping duplicate post: {post_title}") + return recent_posts.append(entry) with open(RECENT_POSTS_FILE, 'w') as f: json.dump(recent_posts, f, indent=2) diff --git a/foodie_weekly_thread.py b/foodie_weekly_thread.py index 2444265..46277aa 100644 --- a/foodie_weekly_thread.py +++ b/foodie_weekly_thread.py @@ -143,7 +143,7 @@ def load_recent_posts(): if not all(key in post for key in required_fields): logging.warning(f"Skipping invalid post: missing fields {post}") continue - datetime.fromisoformat(post["timestamp"]) + datetime.fromisoformat(post["timestamp"].replace('Z', '+00:00')) key = (post["title"], post["url"], post["author_username"]) if key not in unique_posts: unique_posts[key] = post