This commit is contained in:
2025-05-13 19:13:11 +10:00
parent 79cc367579
commit 6e3f055f3a
+55 -4
View File
@@ -353,21 +353,72 @@ def run_rss_automator():
lock_fd = acquire_lock()
update_system_activity(SCRIPT_NAME, "running", os.getpid()) # Record start
logging.info("***** RSS Automator Launched *****")
# Load posted titles and used images
posted_titles_data = load_json_file(POSTED_TITLES_FILE, EXPIRATION_HOURS)
posted_titles = set(entry["title"] for entry in posted_titles_data)
used_images_data = load_json_file(USED_IMAGES_FILE, IMAGE_EXPIRATION_DAYS)
used_images = set(entry["title"] for entry in used_images_data if "title" in entry)
post_data, category, sleep_time = curate_from_rss(posted_titles_data, posted_titles, used_images_data, used_images)
if not post_data:
logging.info("No postable RSS article found")
# Fetch RSS articles
articles = fetch_rss_feeds()
if not articles:
logging.info("No new RSS articles found")
sleep_time = random.randint(1200, 1800) # 2030 minutes
return None, None, sleep_time
# Process each article
for article in articles:
title = article["title"]
if title in posted_titles:
logging.info(f"Skipping already posted article: {title}")
continue
# Extract necessary fields
entry = type('Entry', (), {
'title': title,
'summary': article["summary"],
'link': article["link"]
})()
original_source = article["feed_title"]
source_name = get_clean_source_name(original_source)
link = article["link"]
page_url = link # Use the article link as the page_url
# Curate the article
post_id, post_url = curate_from_rss(entry, original_source, source_name, link, page_url)
if post_id and post_url:
# Prepare post_data for return
post_data = {
"title": title,
"url": post_url,
"id": post_id
}
# Update posted titles
timestamp = datetime.now(timezone.utc).isoformat()
save_json_file(POSTED_TITLES_FILE, title, timestamp)
posted_titles.add(title)
# Determine category (you might need to adjust this based on your actual usage)
category = generate_category_from_summary(article["summary"])
logging.info("Completed RSS run")
update_system_activity(SCRIPT_NAME, "stopped") # Record stop
sleep_time = random.randint(1200, 1800) # 2030 minutes
logging.info(f"Run completed, sleep_time: {sleep_time} seconds")
return post_data, category, sleep_time
# If no articles were posted
logging.info("No postable RSS article found")
update_system_activity(SCRIPT_NAME, "stopped") # Record stop
sleep_time = random.randint(1200, 1800) # 2030 minutes
logging.info(f"Run completed, sleep_time: {sleep_time} seconds")
return None, None, sleep_time
except Exception as e:
logging.error(f"Fatal error in run_rss_automator: {e}", exc_info=True)
update_system_activity(SCRIPT_NAME, "stopped") # Record stop on error
sleep_time = random.randint(1200, 1800) # Fixed to 2030 minutes
sleep_time = random.randint(1200, 1800) # 2030 minutes
logging.info(f"Run completed, sleep_time: {sleep_time} seconds")
return None, None, sleep_time
finally: