add max tweet to author limit
This commit is contained in:
+50
-2
@@ -217,8 +217,8 @@ def post_tweet(author, tweet, reply_to_id=None):
|
||||
if author_count["monthly_count"] >= 500:
|
||||
logging.warning(f"Monthly post limit (500) reached for {author['username']}")
|
||||
return False
|
||||
if author_count["daily_count"] >= 20:
|
||||
logging.warning(f"Daily post limit (20) reached for {author['username']}")
|
||||
if author_count["daily_count"] >= 15: # Updated daily limit
|
||||
logging.warning(f"Daily post limit (15) reached for {author['username']}")
|
||||
return False
|
||||
|
||||
try:
|
||||
@@ -1170,6 +1170,54 @@ def select_best_author(content, interest_score):
|
||||
logging.error(f"Error in select_best_author: {e}")
|
||||
return random.choice(list(PERSONA_CONFIGS.keys()))
|
||||
|
||||
def get_next_author_round_robin():
|
||||
"""Select the next author in a round-robin fashion, respecting daily tweet limits."""
|
||||
last_author_file = "/home/shane/foodie_automator/last_author.json"
|
||||
authors = [author["username"] for author in AUTHORS]
|
||||
post_counts = load_post_counts()
|
||||
|
||||
# Load the last used author
|
||||
try:
|
||||
if os.path.exists(last_author_file):
|
||||
with open(last_author_file, 'r') as f:
|
||||
last_data = json.load(f)
|
||||
last_index = last_data.get("last_index", -1)
|
||||
else:
|
||||
last_index = -1
|
||||
except Exception as e:
|
||||
logging.warning(f"Failed to load last author from {last_author_file}: {e}. Starting from first author.")
|
||||
last_index = -1
|
||||
|
||||
# Find the next author who hasn't reached the daily limit
|
||||
start_index = (last_index + 1) % len(authors)
|
||||
for i in range(len(authors)):
|
||||
current_index = (start_index + i) % len(authors)
|
||||
username = authors[current_index]
|
||||
author_count = next((entry for entry in post_counts if entry["username"] == username), None)
|
||||
if not author_count:
|
||||
logging.error(f"No post count entry for {username}, skipping")
|
||||
continue
|
||||
if author_count["daily_count"] >= 15: # Updated daily limit
|
||||
logging.info(f"Author {username} has reached daily limit ({author_count['daily_count']}/15), skipping")
|
||||
continue
|
||||
if author_count["monthly_count"] >= 500:
|
||||
logging.info(f"Author {username} has reached monthly limit ({author_count['monthly_count']}/500), skipping")
|
||||
continue
|
||||
|
||||
# Save the current index as the last used author
|
||||
try:
|
||||
with open(last_author_file, 'w') as f:
|
||||
json.dump({"last_index": current_index}, f)
|
||||
logging.info(f"Selected author {username} (index {current_index}) in round-robin order")
|
||||
except Exception as e:
|
||||
logging.warning(f"Failed to save last author to {last_author_file}: {e}")
|
||||
|
||||
# Return the selected author
|
||||
return next(author for author in AUTHORS if author["username"] == username)
|
||||
|
||||
logging.warning("No authors available within daily/monthly limits. Selecting a random author as fallback.")
|
||||
return random.choice(AUTHORS)
|
||||
|
||||
def prepare_post_data(summary, title, main_topic=None):
|
||||
try:
|
||||
logging.info(f"Preparing post data for summary: {summary[:100]}...")
|
||||
|
||||
Reference in New Issue
Block a user