Skip to content

Commit bb5f7d9

Browse files
committed
Privacy Substitution Feature
1 parent 96d3d73 commit bb5f7d9

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

instagram_monitor.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@
181181
# Set to True to enable verbose output for HTTP jitter/back-off wrappers
182182
JITTER_VERBOSE = False
183183
184+
# Optional Privacy Substitutions
185+
# This allows you to substitute any string for another in all messaging, logging, and emailing.
186+
# For instance, you may want to change a particular Instagram username to a more friendy name, or you could mask a name.
187+
#
188+
# Provide a list of (search, replace) tuples. Any search term will be substituted with the replace term.
189+
#
190+
# Example:
191+
# PRIVACY_SUBSTITIONS = [ ("a.username", "XXX"), ("sdfsdf747475475", "Bobby") ]
192+
#
193+
PRIVACY_SUBSTITIONS = [ ]
194+
184195
# Optional: specify web browser user agent manually
185196
#
186197
# For session login using Firefox cookies, ensure this matches your Firefox web browser's user agent
@@ -664,6 +675,7 @@ def generate_config_with_current_values() -> str:
664675
THUMBNAILS_FORCED_BY_WEB = False
665676
FOLLOWERS_CHURN_DETECTION = False
666677
TIME_FORMAT_12H = False
678+
PRIVACY_SUBSTITIONS = []
667679
mode_of_the_tool = "Unknown"
668680

669681
exec(CONFIG_BLOCK, globals())
@@ -2865,6 +2877,7 @@ def write(self, message):
28652877
global last_output
28662878
with STDOUT_LOCK:
28672879
# Apply color for terminal
2880+
message = process_message_substitutions(message)
28682881
colorized_message = apply_color_to_text(message)
28692882

28702883
if message != '\n':
@@ -3101,6 +3114,10 @@ def send_email(subject, body, body_html, use_ssl, image_file="", image_name="ima
31013114
fqdn_re = re.compile(r'(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}\.?$)')
31023115
email_re = re.compile(r'[^@]+@[^@]+\.[^@]+')
31033116

3117+
subject = process_message_substitutions(subject)
3118+
body = process_message_substitutions(body)
3119+
body_html = process_message_substitutions(body_html)
3120+
31043121
try:
31053122
ipaddress.ip_address(str(SMTP_HOST))
31063123
except ValueError:
@@ -3333,6 +3350,9 @@ def send_webhook(title, description, color=0x7289DA, fields=None, image_url=None
33333350
if not WEBHOOK_ENABLED or not WEBHOOK_URL:
33343351
return 1
33353352

3353+
title = process_message_substitutions(title)
3354+
description = process_message_substitutions(description)
3355+
33363356
# Validate webhook URL
33373357
if not validate_webhook_url(WEBHOOK_URL):
33383358
debug_print("* Webhook error: Invalid webhook URL format")
@@ -3453,12 +3473,31 @@ def send_webhook(title, description, color=0x7289DA, fields=None, image_url=None
34533473
return 1
34543474

34553475

3476+
def process_message_substitutions(message: str) -> str:
3477+
"""
3478+
Perform search/replace on a message using the PRIVACY_SUBSTITIONS global variable.
3479+
PRIVACY_SUBSTITIONS should be a list of (search, replace) tuples.
3480+
Returns the original message if PRIVACY_SUBSTITIONS doesn't exist or is empty.
3481+
"""
3482+
try:
3483+
if not PRIVACY_SUBSTITIONS:
3484+
return message
3485+
except NameError:
3486+
return message
3487+
3488+
for search, replace in PRIVACY_SUBSTITIONS:
3489+
message = message.replace(search, replace)
3490+
3491+
return message
3492+
3493+
34563494
# Debug print helper - only prints if DEBUG_MODE is enabled
34573495
def debug_print(message):
34583496
if DEBUG_MODE:
3497+
message = process_message_substitutions(message)
34593498
timestamp = get_hour_min_from_ts(now_local(), show_seconds=True)
34603499
user = getattr(_thread_local, 'user', None)
3461-
user_prefix = f" [{user}]" if user else ""
3500+
user_prefix = f" [{process_message_substitutions(user)}]" if user else ""
34623501

34633502
# If we just printed a partial line (no newline), add one before the debug message to avoid clobbering
34643503
if getattr(_thread_local, 'in_partial_line', False):

0 commit comments

Comments
 (0)