From 5e28e33dc0568bb8af32da711eefaecf64d5e62b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Dec 2022 21:33:14 +0000 Subject: [PATCH] Case insensitive --- blocking.py | 12 +++++++++--- followingCalendar.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/blocking.py b/blocking.py index 3e92bfd2a..d4109d780 100644 --- a/blocking.py +++ b/blocking.py @@ -727,12 +727,18 @@ def allowed_announce_add(base_dir: str, nickname: str, domain: str, with open(blocking_filename, 'r', encoding='utf-8') as fp_noannounce: file_text = fp_noannounce.read() - file_text = file_text.replace(handle + '\n', '') - file_text = \ - file_text.replace(handle.lower() + '\n', '') except OSError: print('EX: unable to read noannounce: ' + blocking_filename + ' ' + handle) + + new_file_text = '' + file_text_list = file_text.split('\n') + handle_lower = handle.lower() + for allowed in file_text_list: + if allowed.lower() != handle_lower: + new_file_text += allowed + '\n' + file_text = new_file_text + try: with open(blocking_filename, 'w+', encoding='utf-8') as fp_noannounce: diff --git a/followingCalendar.py b/followingCalendar.py index 0045aeeab..37c291a42 100644 --- a/followingCalendar.py +++ b/followingCalendar.py @@ -144,9 +144,14 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str, # already added return # remove from calendar file - following_handles = following_handles.replace(handle + '\n', '') - following_handles = \ - following_handles.replace(handle.lower() + '\n', '') + new_following_handles = '' + following_handles_list = following_handles.split('\n') + handle_lower = handle.lower() + for followed in following_handles_list: + if followed.lower() != handle_lower: + new_following_handles += followed + '\n' + following_handles = new_following_handles + # save the result try: with open(calendar_filename, 'w+', encoding='utf-8') as fp_cal: