Shane 7 months ago
parent e7a06e3375
commit 4adaa3442c
  1. 5
      foodie_utils.py
  2. 2
      foodie_weekly_thread.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.""" """Save a post to recent_posts.json, maintaining a JSON array."""
try: try:
recent_posts = load_json_file(RECENT_POSTS_FILE, expiration_hours=24) recent_posts = load_json_file(RECENT_POSTS_FILE, expiration_hours=24)
# Check for duplicates before appending
entry = { entry = {
"title": post_title, "title": post_title,
"url": post_url, "url": post_url,
"author_username": author_username, "author_username": author_username,
"timestamp": timestamp "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) recent_posts.append(entry)
with open(RECENT_POSTS_FILE, 'w') as f: with open(RECENT_POSTS_FILE, 'w') as f:
json.dump(recent_posts, f, indent=2) json.dump(recent_posts, f, indent=2)

@ -143,7 +143,7 @@ def load_recent_posts():
if not all(key in post for key in required_fields): if not all(key in post for key in required_fields):
logging.warning(f"Skipping invalid post: missing fields {post}") logging.warning(f"Skipping invalid post: missing fields {post}")
continue continue
datetime.fromisoformat(post["timestamp"]) datetime.fromisoformat(post["timestamp"].replace('Z', '+00:00'))
key = (post["title"], post["url"], post["author_username"]) key = (post["title"], post["url"], post["author_username"])
if key not in unique_posts: if key not in unique_posts:
unique_posts[key] = post unique_posts[key] = post

Loading…
Cancel
Save