From 37ad5349ac55b0d57bd49225a8f507925833987e Mon Sep 17 00:00:00 2001 From: Shane Date: Tue, 13 May 2025 19:21:13 +1000 Subject: [PATCH] fix --- foodie_automator_google.py | 23 +++++++++++++++++------ foodie_automator_reddit.py | 25 ++++++++++++++++++------- foodie_automator_rss.py | 24 +++++++++++++++++++++--- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/foodie_automator_google.py b/foodie_automator_google.py index 30fccac..af2c08b 100644 --- a/foodie_automator_google.py +++ b/foodie_automator_google.py @@ -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): 'Facebook' ) - # 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: diff --git a/foodie_automator_reddit.py b/foodie_automator_reddit.py index c2a5747..4f1eed8 100644 --- a/foodie_automator_reddit.py +++ b/foodie_automator_reddit.py @@ -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): 'Facebook' ) - # 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: diff --git a/foodie_automator_rss.py b/foodie_automator_rss.py index b4c9b88..16ed098 100644 --- a/foodie_automator_rss.py +++ b/foodie_automator_rss.py @@ -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: