This commit is contained in:
2025-05-13 19:21:13 +10:00
parent 6e3f055f3a
commit 37ad5349ac
3 changed files with 56 additions and 16 deletions
+18 -7
View File
@@ -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:
@@ -431,7 +442,7 @@ def curate_from_reddit(post, original_source, source_name, link, page_url):
except Exception as e:
logger.error(f"Error curating Reddit post '{post.get('title', 'unknown')}': {e}")
return None, None
def run_reddit_automator():
lock_fd = None
try: