add max tweet to author limit
This commit is contained in:
+24
-39
@@ -27,7 +27,8 @@ from foodie_utils import (
|
||||
upload_image_to_wp, determine_paragraph_count, insert_link_naturally,
|
||||
is_interesting, generate_title_from_summary, summarize_with_gpt4o,
|
||||
generate_category_from_summary, post_to_wp, prepare_post_data,
|
||||
select_best_author, smart_image_and_filter, get_flickr_image
|
||||
select_best_author, smart_image_and_filter, get_flickr_image,
|
||||
get_next_author_round_robin # Add this line
|
||||
)
|
||||
from foodie_hooks import get_dynamic_hook, get_viral_share_prompt
|
||||
from dotenv import load_dotenv
|
||||
@@ -335,43 +336,31 @@ def curate_from_rss():
|
||||
|
||||
final_summary = insert_link_naturally(final_summary, source_name, link)
|
||||
|
||||
# Insert balanced author selection logic here
|
||||
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] # Authors with <3 posts
|
||||
# Use round-robin author selection
|
||||
author = get_next_author_round_robin()
|
||||
author_username = author["username"]
|
||||
logging.info(f"Selected author via round-robin: {author_username}")
|
||||
|
||||
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)
|
||||
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:
|
||||
print(f"Flickr image fetch failed for '{image_query}', trying fallback")
|
||||
logging.warning(f"Flickr image fetch failed for '{image_query}', trying fallback")
|
||||
image_url, image_source, uploader, page_url = get_image(image_query)
|
||||
if not image_url:
|
||||
print(f"Flickr image fetch failed for '{image_query}', trying fallback")
|
||||
logging.warning(f"Flickr image fetch failed for '{image_query}', trying fallback")
|
||||
image_url, image_source, uploader, page_url = get_image(image_query)
|
||||
if not image_url:
|
||||
print(f"All image uploads failed for '{title}' - posting without image")
|
||||
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:
|
||||
print(f"Post data preparation failed for '{title}'")
|
||||
logging.info(f"Post data preparation failed for '{title}'")
|
||||
attempts += 1
|
||||
continue
|
||||
print(f"All image uploads failed for '{title}' - posting without image")
|
||||
logging.warning(f"All image uploads failed for '{title}' - posting without image")
|
||||
image_source = None
|
||||
uploader = None
|
||||
page_url = None
|
||||
|
||||
# ... (rest of the function: image fetching, posting logic, etc.)
|
||||
hook = get_dynamic_hook(post_data["title"]).strip()
|
||||
|
||||
share_prompt = get_viral_share_prompt(post_data["title"], final_summary)
|
||||
@@ -462,10 +451,6 @@ def curate_from_rss():
|
||||
print("No interesting RSS article found after attempts")
|
||||
logging.info("No interesting RSS article found after attempts")
|
||||
return None, None, random.randint(600, 1800)
|
||||
except Exception as e:
|
||||
print(f"Unexpected error in curate_from_rss: {e}")
|
||||
logging.error(f"Unexpected error in curate_from_rss: {e}", exc_info=True)
|
||||
return None, None, random.randint(600, 1800)
|
||||
|
||||
def run_rss_automator():
|
||||
lock_fd = None
|
||||
|
||||
Reference in New Issue
Block a user