fix stdout flushing

This commit is contained in:
2024-05-26 03:17:10 -05:00
parent 4135f4960e
commit f9e19fb597

16
main.py
View File

@@ -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)