diff --git a/foodie_automator_google.py b/foodie_automator_google.py index bb53fa8..d570bb6 100644 --- a/foodie_automator_google.py +++ b/foodie_automator_google.py @@ -28,7 +28,7 @@ from foodie_utils import ( is_interesting, generate_title_from_summary, summarize_with_gpt4o, generate_category_from_summary, post_to_wp, prepare_post_data, select_best_author, smart_image_and_filter, get_flickr_image, - get_next_author_round_robin, check_author_rate_limit + get_next_author_round_robin, check_author_rate_limit, update_system_activity ) from foodie_hooks import get_dynamic_hook, get_viral_share_prompt from dotenv import load_dotenv @@ -451,6 +451,55 @@ def curate_from_google_trends(posted_titles_data, posted_titles, used_images_dat except Exception as e: logging.error(f"Unexpected error in curate_from_google_trends: {e}", exc_info=True) return None, None, False + +# System Activity Tracking +def update_system_activity(script_name, status, pid=None): + """Update the system activity JSON file with the script's status.""" + activity_file = "/home/shane/foodie_automator/system_activity.json" + activity_data = [] + + # Load existing data + if os.path.exists(activity_file): + try: + with open(activity_file, 'r') as f: + activity_data = json.load(f) + except json.JSONDecodeError: + logging.error("Corrupted system_activity.json, resetting to empty list") + + # Find or create entry for the script + script_entry = next((entry for entry in activity_data if entry["script_name"] == script_name), None) + if not script_entry: + script_entry = { + "script_name": script_name, + "pid": None, + "start_time": None, + "stop_time": None, + "status": "stopped" + } + activity_data.append(script_entry) + + # Update the entry + if status == "running": + script_entry.update({ + "pid": pid, + "start_time": datetime.now(timezone.utc).isoformat(), + "stop_time": None, + "status": "running" + }) + elif status == "stopped": + script_entry.update({ + "pid": None, + "stop_time": datetime.now(timezone.utc).isoformat(), + "status": "stopped" + }) + + # Save updated data + try: + with open(activity_file, 'w') as f: + json.dump(activity_data, f, indent=2) + logging.info(f"Updated system activity: {script_name} is {status}") + except Exception as e: + logging.error(f"Failed to update system_activity.json: {e}") def run_google_trends_automator(): lock_fd = None diff --git a/foodie_automator_reddit.py b/foodie_automator_reddit.py index 3936be9..926d51f 100644 --- a/foodie_automator_reddit.py +++ b/foodie_automator_reddit.py @@ -28,7 +28,7 @@ from foodie_utils import ( is_interesting, generate_title_from_summary, summarize_with_gpt4o, generate_category_from_summary, post_to_wp, prepare_post_data, select_best_author, smart_image_and_filter, get_flickr_image, - get_next_author_round_robin, check_author_rate_limit + get_next_author_round_robin, check_author_rate_limit, update_system_activity ) from foodie_hooks import get_dynamic_hook, get_viral_share_prompt import fcntl diff --git a/foodie_automator_rss.py b/foodie_automator_rss.py index aafd53c..138800f 100644 --- a/foodie_automator_rss.py +++ b/foodie_automator_rss.py @@ -28,7 +28,7 @@ from foodie_utils import ( is_interesting, generate_title_from_summary, summarize_with_gpt4o, generate_category_from_summary, post_to_wp, prepare_post_data, select_best_author, smart_image_and_filter, get_flickr_image, - get_next_author_round_robin, check_author_rate_limit + get_next_author_round_robin, check_author_rate_limit, update_system_activity ) from foodie_hooks import get_dynamic_hook, get_viral_share_prompt from dotenv import load_dotenv diff --git a/foodie_engagement_tweet.py b/foodie_engagement_tweet.py index 94882b5..cb4d9fb 100644 --- a/foodie_engagement_tweet.py +++ b/foodie_engagement_tweet.py @@ -8,7 +8,7 @@ import fcntl import os from datetime import datetime, timedelta, timezone from openai import OpenAI -from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, check_author_rate_limit, load_json_file +from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, check_author_rate_limit, load_json_file, update_system_activity from foodie_config import X_API_CREDENTIALS, AUTHOR_BACKGROUNDS_FILE from dotenv import load_dotenv diff --git a/foodie_weekly_thread.py b/foodie_weekly_thread.py index 1932ac4..3395cfe 100644 --- a/foodie_weekly_thread.py +++ b/foodie_weekly_thread.py @@ -10,7 +10,7 @@ import time from datetime import datetime, timedelta, timezone import tweepy from openai import OpenAI -from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, load_json_file, check_author_rate_limit +from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL, load_json_file, check_author_rate_limit, update_system_activity from foodie_config import X_API_CREDENTIALS, RECENT_POSTS_FILE from dotenv import load_dotenv