|
|
|
@ -56,7 +56,7 @@ def setup_logging(): |
|
|
|
|
|
|
|
|
|
|
|
logging.basicConfig( |
|
|
|
logging.basicConfig( |
|
|
|
filename=LOG_FILE, |
|
|
|
filename=LOG_FILE, |
|
|
|
level=logging.INFO, |
|
|
|
level=logging.DEBUG, # Changed to DEBUG to show more details |
|
|
|
format='%(asctime)s - %(levelname)s - %(message)s', |
|
|
|
format='%(asctime)s - %(levelname)s - %(message)s', |
|
|
|
datefmt='%Y-%m-%d %H:%M:%S' |
|
|
|
datefmt='%Y-%m-%d %H:%M:%S' |
|
|
|
) |
|
|
|
) |
|
|
|
@ -103,9 +103,20 @@ except Exception as e: |
|
|
|
|
|
|
|
|
|
|
|
# Load author backgrounds |
|
|
|
# Load author backgrounds |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
if not os.path.exists(AUTHOR_BACKGROUNDS_FILE): |
|
|
|
|
|
|
|
logging.error(f"Author backgrounds file not found at {AUTHOR_BACKGROUNDS_FILE}") |
|
|
|
|
|
|
|
raise FileNotFoundError(f"Author backgrounds file not found at {AUTHOR_BACKGROUNDS_FILE}") |
|
|
|
with open(AUTHOR_BACKGROUNDS_FILE, 'r') as f: |
|
|
|
with open(AUTHOR_BACKGROUNDS_FILE, 'r') as f: |
|
|
|
AUTHOR_BACKGROUNDS = json.load(f) |
|
|
|
AUTHOR_BACKGROUNDS = json.load(f) |
|
|
|
logging.debug(f"Loaded author backgrounds: {[bg['username'] for bg in AUTHOR_BACKGROUNDS]}") |
|
|
|
if not isinstance(AUTHOR_BACKGROUNDS, list): |
|
|
|
|
|
|
|
logging.error(f"Invalid format in {AUTHOR_BACKGROUNDS_FILE}: Expected a list, got {type(AUTHOR_BACKGROUNDS)}") |
|
|
|
|
|
|
|
raise ValueError("Author backgrounds must be a list") |
|
|
|
|
|
|
|
for bg in AUTHOR_BACKGROUNDS: |
|
|
|
|
|
|
|
if "username" not in bg: |
|
|
|
|
|
|
|
logging.error(f"Invalid entry in {AUTHOR_BACKGROUNDS_FILE}: Missing 'username' key in {bg}") |
|
|
|
|
|
|
|
raise ValueError("Each author background must have a 'username' key") |
|
|
|
|
|
|
|
loaded_usernames = [bg["username"] for bg in AUTHOR_BACKGROUNDS] |
|
|
|
|
|
|
|
logging.debug(f"Loaded author backgrounds: {loaded_usernames}") |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
logging.error(f"Failed to load author_backgrounds.json: {e}", exc_info=True) |
|
|
|
logging.error(f"Failed to load author_backgrounds.json: {e}", exc_info=True) |
|
|
|
AUTHOR_BACKGROUNDS = [] |
|
|
|
AUTHOR_BACKGROUNDS = [] |
|
|
|
@ -172,13 +183,19 @@ def generate_engagement_tweet(author): |
|
|
|
persona = author["persona"] |
|
|
|
persona = author["persona"] |
|
|
|
persona_config = PERSONA_CONFIGS.get(persona, PERSONA_CONFIGS["Visionary Editor"]) |
|
|
|
persona_config = PERSONA_CONFIGS.get(persona, PERSONA_CONFIGS["Visionary Editor"]) |
|
|
|
|
|
|
|
|
|
|
|
# Case-insensitive lookup for background |
|
|
|
# Case-insensitive lookup for background with whitespace stripping |
|
|
|
|
|
|
|
username_cleaned = username.strip().lower() |
|
|
|
background = next( |
|
|
|
background = next( |
|
|
|
(bg for bg in AUTHOR_BACKGROUNDS if bg["username"].lower() == username.lower()), |
|
|
|
(bg for bg in AUTHOR_BACKGROUNDS if bg["username"].strip().lower() == username_cleaned), |
|
|
|
{} |
|
|
|
{} |
|
|
|
) |
|
|
|
) |
|
|
|
if not background or "engagement_themes" not in background: |
|
|
|
if not background or "engagement_themes" not in background: |
|
|
|
logging.warning(f"No background or engagement themes found for {username}, using default theme") |
|
|
|
available_usernames = [bg["username"] for bg in AUTHOR_BACKGROUNDS] |
|
|
|
|
|
|
|
logging.warning( |
|
|
|
|
|
|
|
f"No background or engagement themes found for {username}. " |
|
|
|
|
|
|
|
f"Attempted username (cleaned): {username_cleaned}. " |
|
|
|
|
|
|
|
f"Available usernames: {available_usernames}. Using default theme." |
|
|
|
|
|
|
|
) |
|
|
|
theme = "food trends" |
|
|
|
theme = "food trends" |
|
|
|
else: |
|
|
|
else: |
|
|
|
theme = random.choice(background["engagement_themes"]) |
|
|
|
theme = random.choice(background["engagement_themes"]) |
|
|
|
|