fix better images
This commit is contained in:
+13
-10
@@ -346,7 +346,7 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
posts = fetch_reddit_posts()
|
||||
if not posts:
|
||||
logging.info("No Reddit posts available")
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
sleep_time = random.randint(1200, 1800)
|
||||
return None, None, sleep_time
|
||||
|
||||
attempts = 0
|
||||
@@ -379,8 +379,13 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
|
||||
logging.info(f"Trying Reddit Post: {title} from {source_name}")
|
||||
|
||||
# Combine summary and top comments for smart_image_and_filter
|
||||
enhanced_summary = summary
|
||||
if top_comments:
|
||||
enhanced_summary += "\n\nTop Comments:\n" + "\n".join(top_comments)
|
||||
|
||||
try:
|
||||
image_query, relevance_keywords, main_topic, skip, specific_term = smart_image_and_filter(title, summary)
|
||||
image_query, relevance_keywords, main_topic, skip, specific_term = smart_image_and_filter(title, enhanced_summary)
|
||||
except Exception as e:
|
||||
logging.warning(f"Failed to process smart_image_and_filter for '{title}': {e}")
|
||||
attempts += 1
|
||||
@@ -392,7 +397,6 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
continue
|
||||
|
||||
ddg_context = fetch_duckduckgo_news_context(title)
|
||||
# Log full scoring content for debugging
|
||||
scoring_content = f"Title: {title}\n\nContent: {summary}\n\nTop Comments: {top_comments}\n\nAdditional Context: {ddg_context}"
|
||||
logging.debug(f"Scoring content for '{title}': {scoring_content}")
|
||||
interest_score = is_interesting_reddit(title, summary, upvotes, comment_count, top_comments)
|
||||
@@ -474,11 +478,10 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
)
|
||||
if not post_id:
|
||||
logging.warning(f"Failed to post to WordPress for '{title}', using original URL: {original_url}")
|
||||
post_url = original_url # Fallback to original Reddit post URL
|
||||
post_url = original_url
|
||||
else:
|
||||
logging.info(f"Posted to WordPress for {author_username}: {post_url}")
|
||||
|
||||
# Update post with actual post_url
|
||||
post_url_encoded = quote(post_url)
|
||||
share_links = share_links_template.format(post_url=post_url_encoded)
|
||||
post_data["content"] = f"{final_summary}\n\n{share_links}"
|
||||
@@ -489,7 +492,7 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
category=category,
|
||||
link=link,
|
||||
author=author,
|
||||
image_url=None, # Skip image re-upload
|
||||
image_url=None,
|
||||
original_source=original_source,
|
||||
image_source=image_source,
|
||||
uploader=uploader,
|
||||
@@ -500,7 +503,7 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
)
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to post to WordPress for '{title}': {e}", exc_info=True)
|
||||
post_url = original_url # Fallback to original Reddit post URL
|
||||
post_url = original_url
|
||||
finally:
|
||||
is_posting = False
|
||||
|
||||
@@ -515,15 +518,15 @@ def curate_from_reddit(posted_titles_data, posted_titles, used_images_data, used
|
||||
logging.info(f"Saved image '{image_url}' to {USED_IMAGES_FILE}")
|
||||
|
||||
logging.info(f"***** SUCCESS: Posted '{post_data['title']}' (ID: {post_id or 'N/A'}) from Reddit *****")
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
sleep_time = random.randint(1200, 1800)
|
||||
return post_data, category, sleep_time
|
||||
|
||||
logging.info("No interesting Reddit post found after attempts")
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
sleep_time = random.randint(1200, 1800)
|
||||
return None, None, sleep_time
|
||||
except Exception as e:
|
||||
logging.error(f"Unexpected error in curate_from_reddit: {e}", exc_info=True)
|
||||
sleep_time = random.randint(1200, 1800) # 20–30 minutes
|
||||
sleep_time = random.randint(1200, 1800)
|
||||
return None, None, sleep_time
|
||||
|
||||
def run_reddit_automator():
|
||||
|
||||
Reference in New Issue
Block a user