|
|
|
|
@ -1137,29 +1137,37 @@ def get_flickr_image(search_query, relevance_keywords, main_topic): |
|
|
|
|
logging.warning(f"No valid Flickr image found for query '{search_query}' after all attempts.") |
|
|
|
|
return None, None, None, None |
|
|
|
|
|
|
|
|
|
def select_best_author(summary): |
|
|
|
|
def select_best_author(content, interest_score): |
|
|
|
|
try: |
|
|
|
|
response = client.chat.completions.create( |
|
|
|
|
model=LIGHT_TASK_MODEL, |
|
|
|
|
messages=[ |
|
|
|
|
{"role": "system", "content": ( |
|
|
|
|
"Based on this restaurant/food industry trend summary, pick the most suitable author from: " |
|
|
|
|
"owenjohnson, javiermorales, aishapatel, trangnguyen, keishareid, lilamoreau. " |
|
|
|
|
"Consider their expertise: owenjohnson (global dining trends), javiermorales (food critique), " |
|
|
|
|
"aishapatel (emerging food trends), trangnguyen (cultural dining), keishareid (soul food heritage), " |
|
|
|
|
"lilamoreau (global street food). Return only the username." |
|
|
|
|
)}, |
|
|
|
|
{"role": "user", "content": summary} |
|
|
|
|
], |
|
|
|
|
max_tokens=20 |
|
|
|
|
) |
|
|
|
|
author = response.choices[0].message.content.strip() |
|
|
|
|
valid_authors = ["owenjohnson", "javiermorales", "aishapatel", "trangnguyen", "keishareid", "lilamoreau"] |
|
|
|
|
logging.info(f"Selected author: {author}") |
|
|
|
|
return author if author in valid_authors else "owenjohnson" |
|
|
|
|
x_post_counts = load_json_file('/home/shane/foodie_automator/x_post_counts.json', expiration_hours=24*30) |
|
|
|
|
monthly_counts = {entry['username']: entry['monthly_count'] for entry in x_post_counts} |
|
|
|
|
|
|
|
|
|
best_score = -1 |
|
|
|
|
best_author = None |
|
|
|
|
for author, persona in PERSONA_CONFIGS.items(): |
|
|
|
|
prompt = persona["prompt"] |
|
|
|
|
current_score = interest_score |
|
|
|
|
if "trend" in prompt.lower(): |
|
|
|
|
current_score += 2 |
|
|
|
|
elif "recipe" in prompt.lower(): |
|
|
|
|
current_score += 1 |
|
|
|
|
|
|
|
|
|
# Penalize authors with high post counts |
|
|
|
|
post_count = monthly_counts.get(author, 0) |
|
|
|
|
current_score -= post_count * 0.5 |
|
|
|
|
|
|
|
|
|
if current_score > best_score: |
|
|
|
|
best_score = current_score |
|
|
|
|
best_author = author |
|
|
|
|
|
|
|
|
|
if not best_author: |
|
|
|
|
best_author = min(monthly_counts, key=monthly_counts.get, default=random.choice(list(PERSONA_CONFIGS.keys()))) |
|
|
|
|
|
|
|
|
|
logging.info(f"Selected author: {best_author} with adjusted score: {best_score}") |
|
|
|
|
return best_author |
|
|
|
|
except Exception as e: |
|
|
|
|
logging.error(f"Author selection failed: {e}") |
|
|
|
|
return "owenjohnson" |
|
|
|
|
logging.error(f"Error in select_best_author: {e}") |
|
|
|
|
return random.choice(list(PERSONA_CONFIGS.keys())) |
|
|
|
|
|
|
|
|
|
def prepare_post_data(summary, title, main_topic=None): |
|
|
|
|
try: |
|
|
|
|
|