Skip to content

Commit ac2bd14

Browse files
bakerboy448claude
andcommitted
fix: resolve undefined variables and code quality issues
- Add missing BASE_BACKOFF_WAIT and MAX_BACKOFF_WAIT constants for exponential backoff - Initialize first_run_force variable in continuous mode function - Add sanitize_for_markdown() helper function to eliminate code duplication - Replace all instances of pipe character replacement with consistent helper function - Improves code maintainability and prevents NameError exceptions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 893cb8a commit ac2bd14

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

modlog_wiki_publisher.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
DB_PATH = "modlog.db"
2121
LOGS_DIR = "logs"
22+
BASE_BACKOFF_WAIT = 30
23+
MAX_BACKOFF_WAIT = 300
2224
logger = logging.getLogger(__name__)
2325

2426
# Configuration limits and defaults
@@ -309,6 +311,12 @@ def censor_email_addresses(text):
309311
# Replace email addresses with [EMAIL]
310312
return re.sub(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', '[EMAIL]', text)
311313

314+
def sanitize_for_markdown(text: str) -> str:
315+
"""Sanitize text for use in markdown tables by escaping pipe characters"""
316+
if text is None:
317+
return ""
318+
return str(text).replace("|", " ")
319+
312320
def get_action_datetime(action):
313321
"""Convert action.created_utc to datetime object regardless of input type"""
314322
if isinstance(action.created_utc, (int, float)):
@@ -516,7 +524,7 @@ def store_processed_action(action, subreddit_name=None):
516524
get_target_type(action),
517525
generate_display_id(action),
518526
target_permalink,
519-
removal_reason.replace("|"," ") if removal_reason is not None else None, # Store properly processed removal reason
527+
sanitize_for_markdown(removal_reason), # Store properly processed removal reason
520528
target_author,
521529
int(action.created_utc) if isinstance(action.created_utc, (int, float)) else int(action.created_utc.timestamp()),
522530
subreddit_name or 'unknown'
@@ -728,7 +736,7 @@ def format_content_link(action) -> str:
728736
# Format with link like main branch
729737
if formatted_link:
730738
formatted_title = f"[{formatted_title}]({formatted_link})"
731-
return formatted_title.replace("|"," ")
739+
return sanitize_for_markdown(formatted_title)
732740

733741
def extract_content_id_from_permalink(permalink):
734742
"""Extract the actual post/comment ID from Reddit permalink URL"""
@@ -783,7 +791,7 @@ def format_modlog_entry(action, config: Dict[str, Any]) -> Dict[str, str]:
783791
'id': content_id,
784792
'moderator': get_moderator_name(action, config.get('anonymize_moderators', True)) or 'Unknown',
785793
'content': format_content_link(action),
786-
'reason': str(reason_text).replace("|"," "),
794+
'reason': sanitize_for_markdown(str(reason_text)),
787795
'inquire': generate_modmail_link(config['source_subreddit'], action)
788796
}
789797

@@ -1158,6 +1166,7 @@ def run_continuous_mode(reddit, config: Dict[str, Any], force: bool = False):
11581166

11591167
error_count = 0
11601168
max_errors = config.get('max_continuous_errors', CONFIG_LIMITS['max_continuous_errors']['default'])
1169+
first_run_force = force
11611170

11621171
while True:
11631172
try:

0 commit comments

Comments
 (0)