update cta hooks

This commit is contained in:
2025-05-01 21:01:36 +10:00
parent 472a7ecd94
commit 2d86085867
4 changed files with 78 additions and 46 deletions
+17 -8
View File
@@ -25,14 +25,13 @@ from foodie_utils import (
upload_image_to_wp, determine_paragraph_count, insert_link_naturally,
is_interesting, generate_title_from_summary, summarize_with_gpt4o,
generate_category_from_summary, post_to_wp, prepare_post_data,
select_best_author, smart_image_and_filter, get_flickr_image # Updated function name
select_best_author, smart_image_and_filter, get_flickr_image
)
from foodie_hooks import get_dynamic_hook, select_best_cta
from foodie_hooks import get_dynamic_hook, select_best_cta, get_viral_share_prompt # Added import
from dotenv import load_dotenv
load_dotenv()
# Flag to indicate if we're in the middle of posting
is_posting = False
def signal_handler(sig, frame):
@@ -176,7 +175,7 @@ def fetch_rss_feeds():
continue
logging.info(f"Filtered to {len(articles)} articles from {feed_url}")
except Exception as e:
logging.error(f"Failed to fetch RSS feed {feed_url}: {e}")
logging.error(f"Failed to fetch RSS feed {feed |url}: {e}")
continue
articles.sort(key=lambda x: x["pub_date"], reverse=True)
@@ -252,12 +251,10 @@ def curate_from_rss():
r'\*\*' + re.escape(title) + r'\*\*|' + re.escape(title),
re.IGNORECASE
)
# Split into paragraphs, process each one, then rejoin
paragraphs = final_summary.split('\n')
cleaned_paragraphs = []
for para in paragraphs:
if para.strip():
# Remove the title and normalize spaces within the paragraph
cleaned_para = title_pattern.sub('', para).strip()
cleaned_para = re.sub(r'\s+', ' ', cleaned_para)
cleaned_paragraphs.append(cleaned_para)
@@ -277,7 +274,15 @@ def curate_from_rss():
hook = get_dynamic_hook(post_data["title"]).strip()
cta = select_best_cta(post_data["title"], final_summary, post_url=None)
post_data["content"] = f"{final_summary}\n\n{cta}"
# Generate viral share prompt
share_prompt = get_viral_share_prompt(post_data["title"], final_summary)
share_links_template = (
f'<p>{share_prompt} '
f'<a href="https://x.com/intent/tweet?url={{post_url}}&text={{share_text}}" target="_blank"><i class="tsi tsi-twitter"></i></a> '
f'<a href="https://www.facebook.com/sharer/sharer.php?u={{post_url}}" target="_blank"><i class="tsi tsi-facebook"></i></a></p>'
)
post_data["content"] = f"{final_summary}\n\n{cta}\n\n{share_links_template}"
global is_posting
is_posting = True
try:
@@ -298,8 +303,12 @@ def curate_from_rss():
is_posting = False
if post_id:
share_text = f"Check out this foodie gem! {post_data['title']}"
share_text_encoded = quote(share_text)
post_url_encoded = quote(post_url)
share_links = share_links_template.format(post_url=post_url_encoded, share_text=share_text_encoded)
cta = select_best_cta(post_data["title"], final_summary, post_url=post_url)
post_data["content"] = f"{final_summary}\n\n{cta}"
post_data["content"] = f"{final_summary}\n\n{cta}\n\n{share_links}"
is_posting = True
try:
post_to_wp(