update double tweet & other scripts to new code

This commit is contained in:
2025-05-04 16:15:20 +10:00
parent 4116d5f742
commit 61b3de52a2
4 changed files with 27 additions and 7 deletions
+8 -1
View File
@@ -3,6 +3,7 @@ import logging
from datetime import datetime, timedelta, timezone
from openai import OpenAI # Add this import
from foodie_utils import post_tweet, AUTHORS, SUMMARY_MODEL
from foodie_config import X_API_CREDENTIALS
from dotenv import load_dotenv # Add this import
# Setup logging
@@ -14,8 +15,14 @@ load_dotenv()
# Initialize OpenAI client
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def generate_engagement_tweet(author):
author_handle = author["x_username"] # Updated to use x_username from X_API_CREDENTIALS
# Fetch x_username from X_API_CREDENTIALS
credentials = next((cred for cred in X_API_CREDENTIALS if cred["username"] == author["username"]), None)
if not credentials:
logging.error(f"No X credentials found for {author['username']}")
return None
author_handle = credentials["x_username"]
prompt = (
f"Generate a concise tweet (under 280 characters) for {author_handle}. "
f"Create an engaging food-related question or statement to spark interaction. "