|
|
|
|
@ -109,21 +109,22 @@ def save_json_file(file_path, data, timestamp=None): |
|
|
|
|
logger.error(f"Failed to save {file_path}: {str(e)}") |
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
def generate_article_tweet(author, post, persona): |
|
|
|
|
def generate_article_tweet(author, post, persona, summary=""): |
|
|
|
|
title = post["title"] |
|
|
|
|
url = post["url"] |
|
|
|
|
author_handle = f"@{author['username']}" |
|
|
|
|
|
|
|
|
|
prompt = ( |
|
|
|
|
f"Craft a sharp tweet (under 230 characters) for {author_handle} with the voice of '{persona}'. " |
|
|
|
|
f"Distill the essence of the article '{title}' into a concise, engaging message. " |
|
|
|
|
f"Craft a sharp tweet (under 280 characters) for {author_handle} with the voice of '{persona}'. " |
|
|
|
|
f"Distill the essence of the article '{title}' and its summary into a concise, engaging message. " |
|
|
|
|
f"Summary: {summary}\n" |
|
|
|
|
f"Include one specific detail from the summary (e.g., a unique dish, location, or trend). " |
|
|
|
|
f"Include the raw URL '{url}' at the end. " |
|
|
|
|
f"Do not wrap the tweet in quotation marks. " |
|
|
|
|
f"Make it bold, spark curiosity, and invite engagement with a human touch. " |
|
|
|
|
f"Swap 'elevate' for dynamic terms like 'ignite' or 'unleash'. " |
|
|
|
|
f"Absolutely do not include hashtags, emojis, or phrases like '[Read more]' or 'Read more'. " |
|
|
|
|
f"Skip hashtags, emojis, or phrases like '[Read more]' or 'Read more'. " |
|
|
|
|
f"Skip any extra fluff or formatting around the URL—just append the raw URL after a space. " |
|
|
|
|
f"Example: 'Love food trends? Check this out! {url}'" |
|
|
|
|
f"Example: 'Craving sushi? This Tokyo spot is unreal! {url}'" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
response = client.chat.completions.create( |
|
|
|
|
@ -132,7 +133,7 @@ def generate_article_tweet(author, post, persona): |
|
|
|
|
{"role": "system", "content": "You are a social media viral expert crafting engaging tweets."}, |
|
|
|
|
{"role": "user", "content": prompt} |
|
|
|
|
], |
|
|
|
|
max_tokens=80, |
|
|
|
|
max_tokens=100, |
|
|
|
|
temperature=0.7 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
@ -850,7 +851,8 @@ def post_to_wp(post_data, category, link, author, image_url, original_source, im |
|
|
|
|
"title": post_data["title"], |
|
|
|
|
"url": post_url |
|
|
|
|
} |
|
|
|
|
tweet_text = generate_article_tweet(author, tweet_post, persona) |
|
|
|
|
# Pass the summary to generate_article_tweet |
|
|
|
|
tweet_text = generate_article_tweet(author, tweet_post, persona, summary=summary if summary else post_data["content"]) |
|
|
|
|
tweet_id, tweet_data = post_tweet(author, tweet_text, tweet_type="rss") |
|
|
|
|
if tweet_id: |
|
|
|
|
logger.info(f"Successfully tweeted for post: {post_data['title']} (Tweet ID: {tweet_id})") |
|
|
|
|
|