diff --git a/foodie_engagement_tweet.py b/foodie_engagement_tweet.py index b5eb56a..38e8257 100644 --- a/foodie_engagement_tweet.py +++ b/foodie_engagement_tweet.py @@ -1,8 +1,8 @@ import random import logging -from datetime import datetime +from datetime import datetime, timedelta import openai -from foodie_utils import post_tweet, AUTHORS +from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL # Setup logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') @@ -19,7 +19,7 @@ def generate_engagement_tweet(author): try: response = openai.ChatCompletion.create( - model="gpt-4o", + model=SUMMARY_MODEL, messages=[ {"role": "system", "content": "You are a social media expert crafting engaging tweets."}, {"role": "user", "content": prompt} @@ -44,18 +44,26 @@ def generate_engagement_tweet(author): return template.format(handle=author_handle) def post_engagement_tweet(): - for author in AUTHORS: - tweet = generate_engagement_tweet(author) - - 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']}") - else: - logging.warning(f"Failed to post engagement tweet for {author['username']}") + # Reference date for calculating the 2-day interval + reference_date = datetime(2025, 4, 29, tzinfo=timezone.utc) # Starting from April 29, 2025 + current_date = datetime.now(timezone.utc) + + # Calculate the number of days since the reference date + days_since_reference = (current_date - reference_date).days + + # Post only if the number of days since the reference date is divisible by 2 + if days_since_reference % 2 == 0: + logging.info("Today is an engagement tweet day (every 2 days). Posting...") + for author in AUTHORS: + tweet = generate_engagement_tweet(author) + + 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']}") + else: + logging.warning(f"Failed to post engagement tweet for {author['username']}") + else: + logging.info("Today is not an engagement tweet day (every 2 days). Skipping...") if __name__ == "__main__": - # Run only on Mondays - if datetime.now(timezone.utc).weekday() == 0: # Monday (0 = Monday) - post_engagement_tweet() - else: - logging.info("Not Monday - skipping engagement tweet posting") \ No newline at end of file + post_engagement_tweet() \ No newline at end of file diff --git a/foodie_weekly_thread.py b/foodie_weekly_thread.py index f576f54..b2d6987 100644 --- a/foodie_weekly_thread.py +++ b/foodie_weekly_thread.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta import logging import random import openai -from foodie_utils import post_tweet, AUTHORS +from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL # Setup logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') @@ -46,7 +46,7 @@ def generate_intro_tweet(author): try: response = openai.ChatCompletion.create( - model="gpt-4o", + model=SUMMARY_MODEL, messages=[ {"role": "system", "content": "You are a social media expert crafting engaging tweets."}, {"role": "user", "content": prompt} diff --git a/generate_backgrounds.py b/generate_backgrounds.py deleted file mode 100644 index 0b5cadc..0000000 --- a/generate_backgrounds.py +++ /dev/null @@ -1,55 +0,0 @@ -import json -import logging -from openai import OpenAI -from foodie_config import OPENAI_API_KEY, AUTHORS, LIGHT_TASK_MODEL -from datetime import datetime, timezone - -logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") - -client = OpenAI(api_key=OPENAI_API_KEY) - -def generate_background(author): - # Include the DOB in the prompt to contextualize the timeline - dob = author.get('dob', '1980-01-01') # Fallback DOB if not provided - current_year = datetime.now().year - birth_year = int(dob.split('-')[0]) - age = current_year - birth_year # Calculate approximate age - - prompt = ( - f"Generate a fictional background for a food writer named {author['username']} with the persona '{author['persona']}'. " - f"They were born on {dob} and are currently {age} years old. Use this to create a realistic timeline for their life events. " - "Include: hometown, cultural influences, an early food memory (from their childhood, appropriate for their birth year), " - "and how they became a food writer (considering their age and career timeline). " - f"Match the tone of their bio: '{author['bio']}'. Keep it concise (100-150 words). " - "Return as JSON: {'username': '...', 'hometown': '...', 'cultural_influences': '...', 'early_memory': '...', 'career_path': '...'}" - ) - try: - response = client.chat.completions.create( - model=LIGHT_TASK_MODEL, - messages=[ - {"role": "system", "content": prompt}, - {"role": "user", "content": f"Generate background for {author['username']}."} - ], - max_tokens=200 - ) - raw_result = response.choices[0].message.content.strip() - cleaned_result = raw_result.replace('```json', '').replace('```', '').strip() - return json.loads(cleaned_result) - except Exception as e: - logging.error(f"Failed to generate background for {author['username']}: {e}") - return None - -def main(): - backgrounds = [] - for author in AUTHORS: - background = generate_background(author) - if background: - backgrounds.append(background) - logging.info(f"Generated background for {author['username']}") - - with open('/home/shane/foodie_automator/author_backgrounds.json', 'w') as f: - json.dump(backgrounds, f, indent=2) - logging.info("Saved backgrounds to author_backgrounds.json") - -if __name__ == "__main__": - main() \ No newline at end of file