balanced author selection logic

This commit is contained in:
2025-05-07 09:39:32 +10:00
parent 4da83f1d4b
commit f6ab7e78d3
4 changed files with 122 additions and 52 deletions
+29 -7
View File
@@ -314,14 +314,36 @@ def curate_from_google_trends(geo_list=['US']):
final_summary = insert_link_naturally(final_summary, source_name, link)
post_data, author, category, image_url, image_source, uploader, page_url = prepare_post_data(final_summary, title, main_topic)
if not post_data:
attempts += 1
continue
# Balanced author selection
x_post_counts = load_json_file('/home/shane/foodie_automator/x_post_counts.json', expiration_hours=24*30)
monthly_counts = {entry['username']: entry['monthly_count'] for entry in x_post_counts}
low_post_authors = [u for u, c in monthly_counts.items() if c < 3]
image_url, image_source, uploader, page_url = get_flickr_image(image_query, relevance_keywords, main_topic)
if not image_url:
image_url, image_source, uploader, page_url = get_image(image_query)
if low_post_authors:
author_username = random.choice(low_post_authors)
author = next(a for a in AUTHORS if a['username'] == author_username)
logging.info(f"Prioritizing low-post author: {author_username}")
post_data = {
"title": generate_title_from_summary(final_summary),
"content": final_summary,
"status": "publish",
"author": author_username,
"categories": [generate_category_from_summary(final_summary)]
}
category = post_data["categories"][0]
image_url, image_source, uploader, page_url = get_flickr_image(image_query, relevance_keywords, main_topic)
if not image_url:
image_url, image_source, uploader, page_url = get_image(image_query)
if not image_url:
logging.warning(f"All image uploads failed for '{title}' - posting without image")
image_source = None
uploader = None
page_url = None
else:
post_data, author, category, image_url, image_source, uploader, page_url = prepare_post_data(final_summary, title, main_topic)
if not post_data:
attempts += 1
continue
hook = get_dynamic_hook(post_data["title"]).strip()