fix
This commit is contained in:
@@ -303,7 +303,6 @@ def curate_from_google(item, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to summarize Google item: {item.get('title', 'unknown')}")
|
||||
return None, None
|
||||
|
||||
# Remove the original title from the summary if present
|
||||
if item.get('title', '') in summary:
|
||||
summary = summary.replace(item.get('title', ''), "").strip()
|
||||
while "\n\n\n" in summary:
|
||||
@@ -314,11 +313,24 @@ def curate_from_google(item, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to insert link for Google item: {item.get('title', 'unknown')}")
|
||||
return None, None
|
||||
|
||||
post_data, author, category, image_url, image_source, uploader, page_url = prepare_post_data(final_summary, item.get('title', 'unknown'))
|
||||
if not post_data:
|
||||
result = prepare_post_data(final_summary, item.get('title', 'unknown'))
|
||||
if not result:
|
||||
logger.info(f"Post preparation failed for Google item: {item.get('title', 'unknown')}")
|
||||
return None, None
|
||||
|
||||
logger.debug(f"prepare_post_data returned {len(result)} values: {result}")
|
||||
if len(result) < 7:
|
||||
logger.error(f"prepare_post_data returned too few values: {result}")
|
||||
return None, None
|
||||
|
||||
post_data = result[0]
|
||||
author = result[1]
|
||||
category = result[2]
|
||||
image_url = result[3]
|
||||
image_source = result[4]
|
||||
uploader = result[5]
|
||||
page_url = result[6]
|
||||
|
||||
share_text = f"Check out this tasty find: {post_data['title']}"
|
||||
share_text_encoded = quote(share_text)
|
||||
share_links_template = (
|
||||
@@ -327,7 +339,6 @@ def curate_from_google(item, original_source, source_name, link, page_url):
|
||||
'<a href="https://www.facebook.com/sharer/sharer.php?u={post_url}">Facebook</a>'
|
||||
)
|
||||
|
||||
# First call: Post without share links
|
||||
post_data["content"] = final_summary
|
||||
post_id, post_url = post_to_wp(
|
||||
post_data=post_data,
|
||||
@@ -348,7 +359,6 @@ def curate_from_google(item, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to post Google item to WP: {post_data['title']}")
|
||||
return None, None
|
||||
|
||||
# Second call: Update with share links
|
||||
post_url_encoded = quote(post_url)
|
||||
share_links = share_links_template.format(post_url=post_url_encoded, share_text=share_text_encoded)
|
||||
post_data["content"] = f"{final_summary}\n\n{share_links}"
|
||||
@@ -364,7 +374,8 @@ def curate_from_google(item, original_source, source_name, link, page_url):
|
||||
page_url=page_url,
|
||||
interest_score=interest_score,
|
||||
post_id=post_id,
|
||||
should_post_tweet=False
|
||||
should_post_tweet=False,
|
||||
summary=final_summary
|
||||
)
|
||||
|
||||
if post_id:
|
||||
|
||||
@@ -357,7 +357,6 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to summarize Reddit post: {post.title}")
|
||||
return None, None
|
||||
|
||||
# Remove the original title from the summary if present
|
||||
if post.title in summary:
|
||||
summary = summary.replace(post.title, "").strip()
|
||||
while "\n\n\n" in summary:
|
||||
@@ -368,11 +367,24 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to insert link for Reddit post: {post.title}")
|
||||
return None, None
|
||||
|
||||
post_data, author, category, image_url, image_source, uploader, page_url = prepare_post_data(final_summary, post.title)
|
||||
if not post_data:
|
||||
result = prepare_post_data(final_summary, post.title)
|
||||
if not result:
|
||||
logger.info(f"Post preparation failed for Reddit post: {post.title}")
|
||||
return None, None
|
||||
|
||||
logger.debug(f"prepare_post_data returned {len(result)} values: {result}")
|
||||
if len(result) < 7:
|
||||
logger.error(f"prepare_post_data returned too few values: {result}")
|
||||
return None, None
|
||||
|
||||
post_data = result[0]
|
||||
author = result[1]
|
||||
category = result[2]
|
||||
image_url = result[3]
|
||||
image_source = result[4]
|
||||
uploader = result[5]
|
||||
page_url = result[6]
|
||||
|
||||
share_text = f"Check out this tasty find: {post_data['title']}"
|
||||
share_text_encoded = quote(share_text)
|
||||
share_links_template = (
|
||||
@@ -381,7 +393,6 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
|
||||
'<a href="https://www.facebook.com/sharer/sharer.php?u={post_url}">Facebook</a>'
|
||||
)
|
||||
|
||||
# First call: Post without share links
|
||||
post_data["content"] = final_summary
|
||||
post_id, post_url = post_to_wp(
|
||||
post_data=post_data,
|
||||
@@ -402,7 +413,6 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to post Reddit post to WP: {post_data['title']}")
|
||||
return None, None
|
||||
|
||||
# Second call: Update with share links
|
||||
post_url_encoded = quote(post_url)
|
||||
share_links = share_links_template.format(post_url=post_url_encoded, share_text=share_text_encoded)
|
||||
post_data["content"] = f"{final_summary}\n\n{share_links}"
|
||||
@@ -418,7 +428,8 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
|
||||
page_url=page_url,
|
||||
interest_score=interest_score,
|
||||
post_id=post_id,
|
||||
should_post_tweet=False
|
||||
should_post_tweet=False,
|
||||
summary=final_summary
|
||||
)
|
||||
|
||||
if post_id:
|
||||
|
||||
+21
-3
@@ -283,11 +283,28 @@ def curate_from_rss(entry, original_source, source_name, link, page_url):
|
||||
logger.warning(f"Failed to insert link for RSS entry: {entry.title}")
|
||||
return None, None
|
||||
|
||||
post_data, author, category, image_url, image_source, uploader, page_url = prepare_post_data(final_summary, entry.title)
|
||||
if not post_data:
|
||||
# Call prepare_post_data and handle return values dynamically
|
||||
result = prepare_post_data(final_summary, entry.title)
|
||||
if not result:
|
||||
logger.info(f"Post preparation failed for RSS entry: {entry.title}")
|
||||
return None, None
|
||||
|
||||
# Log the number of values returned for debugging
|
||||
logger.debug(f"prepare_post_data returned {len(result)} values: {result}")
|
||||
|
||||
# Expect at least 7 values; handle additional values gracefully
|
||||
if len(result) < 7:
|
||||
logger.error(f"prepare_post_data returned too few values: {result}")
|
||||
return None, None
|
||||
|
||||
post_data = result[0]
|
||||
author = result[1]
|
||||
category = result[2]
|
||||
image_url = result[3]
|
||||
image_source = result[4]
|
||||
uploader = result[5]
|
||||
page_url = result[6]
|
||||
|
||||
share_text = f"Check out this tasty find: {post_data['title']}"
|
||||
share_text_encoded = quote(share_text)
|
||||
share_links_template = (
|
||||
@@ -333,7 +350,8 @@ def curate_from_rss(entry, original_source, source_name, link, page_url):
|
||||
page_url=page_url,
|
||||
interest_score=interest_score,
|
||||
post_id=post_id,
|
||||
should_post_tweet=False
|
||||
should_post_tweet=False,
|
||||
summary=final_summary
|
||||
)
|
||||
|
||||
if post_id:
|
||||
|
||||
Reference in New Issue
Block a user