|
|
|
|
@ -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) |
|
|
|
|
|