|
|
|
|
@ -23,6 +23,20 @@ import feedparser |
|
|
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed |
|
|
|
|
from typing import List, Dict, Any, Optional |
|
|
|
|
|
|
|
|
|
# Flag to indicate if we're in the middle of posting |
|
|
|
|
is_posting = False |
|
|
|
|
|
|
|
|
|
def signal_handler(sig, frame): |
|
|
|
|
logging.info("Received termination signal, checking if safe to exit...") |
|
|
|
|
if is_posting: |
|
|
|
|
logging.info("Currently posting, will exit after completion.") |
|
|
|
|
else: |
|
|
|
|
logging.info("Safe to exit immediately.") |
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
|
|
signal.signal(signal.SIGTERM, signal_handler) |
|
|
|
|
signal.signal(signal.SIGINT, signal_handler) |
|
|
|
|
|
|
|
|
|
LOG_FILE = "/home/shane/foodie_automator/foodie_automator_rss.log" |
|
|
|
|
LOG_PRUNE_DAYS = 30 |
|
|
|
|
MAX_WORKERS = 5 # Number of concurrent workers for parallel processing |
|
|
|
|
@ -266,6 +280,9 @@ def curate_from_rss(): |
|
|
|
|
cta = select_best_cta(post_data["title"], final_summary, post_url=None) |
|
|
|
|
|
|
|
|
|
post_data["content"] = f"{final_summary}\n\n{cta}" |
|
|
|
|
global is_posting |
|
|
|
|
is_posting = True |
|
|
|
|
try: |
|
|
|
|
post_id, post_url = post_to_wp( |
|
|
|
|
post_data=post_data, |
|
|
|
|
category=category, |
|
|
|
|
@ -278,10 +295,14 @@ def curate_from_rss(): |
|
|
|
|
pixabay_url=pixabay_url, |
|
|
|
|
interest_score=interest_score |
|
|
|
|
) |
|
|
|
|
finally: |
|
|
|
|
is_posting = False |
|
|
|
|
|
|
|
|
|
if post_id: |
|
|
|
|
cta = select_best_cta(post_data["title"], final_summary, post_url=post_url) |
|
|
|
|
post_data["content"] = f"{final_summary}\n\n{cta}" |
|
|
|
|
is_posting = True |
|
|
|
|
try: |
|
|
|
|
post_to_wp( |
|
|
|
|
post_data=post_data, |
|
|
|
|
category=category, |
|
|
|
|
@ -295,6 +316,8 @@ def curate_from_rss(): |
|
|
|
|
interest_score=interest_score, |
|
|
|
|
post_id=post_id |
|
|
|
|
) |
|
|
|
|
finally: |
|
|
|
|
is_posting = False |
|
|
|
|
|
|
|
|
|
timestamp = datetime.now(timezone.utc).isoformat() |
|
|
|
|
save_json_file(POSTED_TITLES_FILE, title, timestamp) |
|
|
|
|
|