fix stdout flushing
This commit is contained in:
16
main.py
16
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)
|
Reference in New Issue
Block a user