update better tweet for article summary

main
Shane 7 months ago
parent 00e6354cff
commit d7593f7fa7
  1. 3
      foodie_automator_google.py
  2. 3
      foodie_automator_reddit.py
  3. 3
      foodie_automator_rss.py
  4. 18
      foodie_utils.py

@ -372,7 +372,8 @@ def curate_from_google_trends(posted_titles_data, posted_titles, used_images_dat
uploader=uploader, uploader=uploader,
page_url=page_url, page_url=page_url,
interest_score=interest_score, interest_score=interest_score,
should_post_tweet=True should_post_tweet=True,
summary=final_summary
) )
if not post_id: if not post_id:
logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}") logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}")

@ -392,7 +392,8 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
uploader=uploader, uploader=uploader,
page_url=page_url, page_url=page_url,
interest_score=interest_score, interest_score=interest_score,
should_post_tweet=True should_post_tweet=True,
summary=final_summary
) )
if not post_id: if not post_id:
logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}") logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}")

@ -382,7 +382,8 @@ def curate_from_rss(posted_titles_data, posted_titles, used_images_data, used_im
uploader=uploader, uploader=uploader,
page_url=page_url, page_url=page_url,
interest_score=interest_score, interest_score=interest_score,
should_post_tweet=True should_post_tweet=True,
summary=final_summary
) )
if not post_id: if not post_id:
logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}") logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}")

@ -109,21 +109,22 @@ def save_json_file(file_path, data, timestamp=None):
logger.error(f"Failed to save {file_path}: {str(e)}") logger.error(f"Failed to save {file_path}: {str(e)}")
return False return False
def generate_article_tweet(author, post, persona): def generate_article_tweet(author, post, persona, summary=""):
title = post["title"] title = post["title"]
url = post["url"] url = post["url"]
author_handle = f"@{author['username']}" author_handle = f"@{author['username']}"
prompt = ( prompt = (
f"Craft a sharp tweet (under 230 characters) for {author_handle} with the voice of '{persona}'. " f"Craft a sharp tweet (under 280 characters) for {author_handle} with the voice of '{persona}'. "
f"Distill the essence of the article '{title}' into a concise, engaging message. " 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"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"Make it bold, spark curiosity, and invite engagement with a human touch. "
f"Swap 'elevate' for dynamic terms like 'ignite' or 'unleash'. " 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"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( 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": "system", "content": "You are a social media viral expert crafting engaging tweets."},
{"role": "user", "content": prompt} {"role": "user", "content": prompt}
], ],
max_tokens=80, max_tokens=100,
temperature=0.7 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"], "title": post_data["title"],
"url": post_url "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") tweet_id, tweet_data = post_tweet(author, tweet_text, tweet_type="rss")
if tweet_id: if tweet_id:
logger.info(f"Successfully tweeted for post: {post_data['title']} (Tweet ID: {tweet_id})") logger.info(f"Successfully tweeted for post: {post_data['title']} (Tweet ID: {tweet_id})")

Loading…
Cancel
Save