from foodie_config import OPENAI_API_KEY, LIGHT_TASK_MODEL
from openai import OpenAI
import logging
import random
from urllib.parse import quote
client = OpenAI(api_key=OPENAI_API_KEY)
def get_dynamic_hook(article_title):
try:
response = client.chat.completions.create(
model=LIGHT_TASK_MODEL,
messages=[
{"role": "system", "content": (
"Generate a short, catchy hook (under 100 characters) for a tweet based on this article title about food topics. "
"Make it bold and quirky with Upworthy/Buzzfeed flair (e.g., 'This food twist is wild!'), avoiding clichés like 'game-changer'. "
"Do not include emojis in the hook. "
"Return only the hook text."
)},
{"role": "user", "content": article_title}
],
max_tokens=30
)
hook = response.choices[0].message.content.strip().replace('**', '')
logging.info(f"Generated dynamic hook: {hook}")
return hook
except Exception as e:
logging.error(f"Dynamic hook generation failed: {e}")
return "This food scoop will blow your mind!"
def select_best_cta(title, content, post_url=None):
cta_templates = [
# Share-focused CTAs
"Cant Get Enough Share This Now On ",
"This Blew Your Mind Right Tweet It On ",
"Ready to Spill the Tea Share On ",
"Too Wild to Keep Quiet Post It On ",
# Like-focused CTAs
"Love This Foodie Find Hit That Like Button",
"Think This Dish Is a Game Changer Show Some Love With a Like",
# Follow-focused CTAs
"Hungry for More Foodie Insights Follow Us for the Latest Trends",
"Dont Miss Out on Foodie Updates Follow Us Today"
]
hook = get_dynamic_hook(title).strip()
hook = urllib.parse.quote(hook)
url = post_url if post_url else "https://insiderfoodie.com/placeholder"
url = urllib.parse.quote(url)
cta = random.choice(cta_templates)
if "https://x.com/intent/tweet" in cta:
cta = cta.format(url=url, text=hook)
return cta