From f9e19fb59754becaa304f37079f7434a45877024 Mon Sep 17 00:00:00 2001 From: Daniel Tam Date: Sun, 26 May 2024 03:17:10 -0500 Subject: [PATCH] fix stdout flushing --- main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 92651bd..923740d 100644 --- a/main.py +++ b/main.py @@ -28,10 +28,13 @@ nl = '\n' # Config error message def config_error(msg): - print(f'Error parsing config file: {msg}') - sys.stdout.flush() + print_and_flush(f'Error parsing config file: {msg}') sys.exit(1) +def print_and_flush(msg): + print(msg) + sys.stdout.flush() + # Read config file def get_config(filename): config = {} @@ -44,8 +47,7 @@ def get_config(filename): raise configparser.Error except configparser.Error as e: - print(f'Error reading config file {e}') - sys.stdout.flush() + print_and_flush(f'Error reading config file {e}') sys.exit(1) # Parse config file @@ -172,14 +174,12 @@ def send_alert(config, title, text, url, timestamp, keyword): server.sendmail(smtp_from, smtp_to, text) except Exception as e: - print(f'SMTP Send Error: {e}') - sys.stdout.flush() + print_and_flush(f'SMTP Send Error: {e}') if __name__ == '__main__': config = get_config(args.config) - print(f'Current config file: {config}') - sys.stdout.flush() + print_and_flush(f'Current config file: {config}') check_reddit(config) \ No newline at end of file