update real time rate limiting checks for X
This commit is contained in:
+12
-18
@@ -253,15 +253,9 @@ def fetch_duckduckgo_news_context(title, hours=24):
|
||||
logging.error(f"Failed to fetch DuckDuckGo News context for '{title}' after {MAX_RETRIES} attempts")
|
||||
return title
|
||||
|
||||
def curate_from_rss():
|
||||
def curate_from_rss(posted_titles_data, posted_titles, used_images_data, used_images):
|
||||
try:
|
||||
global posted_titles_data, posted_titles, used_images
|
||||
# Load JSON files once
|
||||
posted_titles_data = load_json_file(POSTED_TITLES_FILE, EXPIRATION_HOURS)
|
||||
posted_titles = set(entry["title"] for entry in posted_titles_data)
|
||||
used_images_data = load_json_file(USED_IMAGES_FILE, IMAGE_EXPIRATION_DAYS)
|
||||
used_images = set(entry["title"] for entry in used_images_data if "title" in entry)
|
||||
logging.debug(f"Loaded {len(posted_titles)} posted titles and {len(used_images)} used images")
|
||||
logging.debug(f"Using {len(posted_titles)} posted titles and {len(used_images)} used images")
|
||||
|
||||
articles = fetch_rss_feeds()
|
||||
if not articles:
|
||||
@@ -283,6 +277,16 @@ def curate_from_rss():
|
||||
attempts += 1
|
||||
continue
|
||||
|
||||
# Check author availability before GPT calls
|
||||
author = get_next_author_round_robin()
|
||||
if not author:
|
||||
logging.info(f"Skipping article '{title}' due to tweet rate limits for all authors")
|
||||
attempts += 1
|
||||
continue
|
||||
|
||||
author_username = author["username"]
|
||||
logging.info(f"Selected author via round-robin: {author_username}")
|
||||
|
||||
logging.info(f"Trying RSS Article: {title} from {source_name}")
|
||||
|
||||
try:
|
||||
@@ -330,11 +334,6 @@ def curate_from_rss():
|
||||
|
||||
final_summary = insert_link_naturally(final_summary, source_name, link)
|
||||
|
||||
# Select author
|
||||
author = get_next_author_round_robin()
|
||||
author_username = author["username"]
|
||||
logging.info(f"Selected author via round-robin: {author_username}")
|
||||
|
||||
post_data = {
|
||||
"title": generate_title_from_summary(final_summary),
|
||||
"content": final_summary,
|
||||
@@ -362,8 +361,6 @@ def curate_from_rss():
|
||||
f'<a href="https://x.com/intent/tweet?url={{post_url}}&text={share_text_encoded}" target="_blank"><i class="tsi tsi-twitter"></i></a> '
|
||||
f'<a href="https://www.facebook.com/sharer/sharer.php?u={{post_url}}" target="_blank"><i class="tsi tsi-facebook"></i></a></p>'
|
||||
)
|
||||
|
||||
# Prepare post content with share links placeholder
|
||||
post_data["content"] = f"{final_summary}\n\n{share_links_template}"
|
||||
|
||||
global is_posting
|
||||
@@ -426,9 +423,6 @@ def curate_from_rss():
|
||||
logging.info(f"***** SUCCESS: Posted '{post_data['title']}' (ID: {post_id}) from RSS *****")
|
||||
return post_data, category, random.randint(0, 1800)
|
||||
|
||||
attempts += 1
|
||||
logging.info(f"WP posting failed for '{post_data['title']}'")
|
||||
|
||||
logging.info("No interesting RSS article found after attempts")
|
||||
return None, None, random.randint(600, 1800)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user