fix
This commit is contained in:
@@ -6,6 +6,7 @@ import signal
|
||||
import sys
|
||||
import fcntl
|
||||
import os
|
||||
import time
|
||||
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, update_system_activity
|
||||
@@ -118,7 +119,7 @@ def generate_engagement_tweet(author):
|
||||
theme = random.choice(background["engagement_themes"])
|
||||
|
||||
prompt = (
|
||||
f"Generate a concise tweet (under 280 characters) for {author_handle}. "
|
||||
f"Generate a concise tweet (under 230 characters) for {author_handle}. "
|
||||
f"Create an engaging question or statement about {theme} to spark interaction. "
|
||||
f"Include a call to action to follow {author_handle} or like the tweet, and mention InsiderFoodie.com with a link to https://insiderfoodie.com. "
|
||||
f"Avoid using the word 'elevate'—use more humanized language like 'level up' or 'bring to life'. "
|
||||
@@ -161,6 +162,7 @@ def post_engagement_tweet():
|
||||
"""Post engagement tweets for authors daily."""
|
||||
try:
|
||||
logging.info("Starting foodie_engagement_tweet.py")
|
||||
posted = False
|
||||
|
||||
for author in AUTHORS:
|
||||
# Check if the author can post before generating the tweet
|
||||
@@ -179,6 +181,7 @@ def post_engagement_tweet():
|
||||
logging.info(f"Posting engagement tweet for {author['username']}: {tweet}")
|
||||
if post_tweet(author, tweet):
|
||||
logging.info(f"Successfully posted engagement tweet for {author['username']}")
|
||||
posted = True
|
||||
else:
|
||||
logging.warning(f"Failed to post engagement tweet for {author['username']}")
|
||||
except Exception as e:
|
||||
@@ -186,8 +189,12 @@ def post_engagement_tweet():
|
||||
continue
|
||||
|
||||
logging.info("Completed foodie_engagement_tweet.py")
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
return posted, sleep_time
|
||||
except Exception as e:
|
||||
logging.error(f"Unexpected error in post_engagement_tweet: {e}", exc_info=True)
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
return False, sleep_time
|
||||
|
||||
def main():
|
||||
"""Main function to run the script."""
|
||||
@@ -196,14 +203,17 @@ def main():
|
||||
lock_fd = acquire_lock()
|
||||
setup_logging()
|
||||
update_system_activity(SCRIPT_NAME, "running", os.getpid()) # Record start
|
||||
post_engagement_tweet()
|
||||
posted, sleep_time = post_engagement_tweet()
|
||||
update_system_activity(SCRIPT_NAME, "stopped") # Record stop
|
||||
sys.exit(0)
|
||||
logging.info(f"Run completed, sleep_time: {sleep_time} seconds")
|
||||
return posted, sleep_time
|
||||
except Exception as e:
|
||||
logging.error(f"Fatal error in main: {e}", exc_info=True)
|
||||
print(f"Fatal error: {e}")
|
||||
update_system_activity(SCRIPT_NAME, "stopped") # Record stop on error
|
||||
sys.exit(1)
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
logging.info(f"Run completed, sleep_time: {sleep_time} seconds")
|
||||
return False, sleep_time
|
||||
finally:
|
||||
if lock_fd:
|
||||
fcntl.flock(lock_fd, fcntl.LOCK_UN)
|
||||
@@ -211,4 +221,4 @@ def main():
|
||||
os.remove(LOCK_FILE) if os.path.exists(LOCK_FILE) else None
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
posted, sleep_time = main()
|
||||
Reference in New Issue
Block a user