add new system_activity.json for rate limit X posts

This commit is contained in:
2025-05-12 14:24:43 +10:00
parent 765967fb8c
commit 941fe12ec5
6 changed files with 188 additions and 53 deletions
+6 -1
View File
@@ -37,6 +37,7 @@ import fcntl
load_dotenv()
# Define constants at the top
SCRIPT_NAME = "foodie_automator_google" # Added SCRIPT_NAME
POSTED_TITLES_FILE = '/home/shane/foodie_automator/posted_google_titles.json'
USED_IMAGES_FILE = '/home/shane/foodie_automator/used_images.json'
EXPIRATION_HOURS = 24
@@ -52,7 +53,8 @@ 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)
def signal_handler(sig, frame):
logging.info("Received termination signal, checking if safe to exit...")
logging.info("Received termination signal, marking script as stopped...")
update_system_activity(SCRIPT_NAME, "stopped") # Added to mark as stopped
if is_posting:
logging.info("Currently posting, will exit after completion.")
else:
@@ -454,6 +456,7 @@ def run_google_trends_automator():
lock_fd = None
try:
lock_fd = acquire_lock()
update_system_activity(SCRIPT_NAME, "running", os.getpid()) # Record start
logging.info("***** Google Trends Automator Launched *****")
# Load JSON files once
posted_titles_data = load_json_file(POSTED_TITLES_FILE, EXPIRATION_HOURS)
@@ -464,9 +467,11 @@ def run_google_trends_automator():
if not post_data:
logging.info("No postable Google Trend found")
logging.info("Completed Google Trends run")
update_system_activity(SCRIPT_NAME, "stopped") # Record stop
return post_data, category, should_continue
except Exception as e:
logging.error(f"Fatal error in run_google_trends_automator: {e}", exc_info=True)
update_system_activity(SCRIPT_NAME, "stopped") # Record stop on error
return None, None, False
finally:
if lock_fd: