fix stdout flushing
This commit is contained in:
16
main.py
16
main.py
@@ -28,10 +28,13 @@ nl = '\n'
|
|||||||
|
|
||||||
# Config error message
|
# Config error message
|
||||||
def config_error(msg):
|
def config_error(msg):
|
||||||
print(f'Error parsing config file: {msg}')
|
print_and_flush(f'Error parsing config file: {msg}')
|
||||||
sys.stdout.flush()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def print_and_flush(msg):
|
||||||
|
print(msg)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
# Read config file
|
# Read config file
|
||||||
def get_config(filename):
|
def get_config(filename):
|
||||||
config = {}
|
config = {}
|
||||||
@@ -44,8 +47,7 @@ def get_config(filename):
|
|||||||
raise configparser.Error
|
raise configparser.Error
|
||||||
|
|
||||||
except configparser.Error as e:
|
except configparser.Error as e:
|
||||||
print(f'Error reading config file {e}')
|
print_and_flush(f'Error reading config file {e}')
|
||||||
sys.stdout.flush()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Parse config file
|
# Parse config file
|
||||||
@@ -172,14 +174,12 @@ def send_alert(config, title, text, url, timestamp, keyword):
|
|||||||
|
|
||||||
server.sendmail(smtp_from, smtp_to, text)
|
server.sendmail(smtp_from, smtp_to, text)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'SMTP Send Error: {e}')
|
print_and_flush(f'SMTP Send Error: {e}')
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
config = get_config(args.config)
|
config = get_config(args.config)
|
||||||
|
|
||||||
print(f'Current config file: {config}')
|
print_and_flush(f'Current config file: {config}')
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
check_reddit(config)
|
check_reddit(config)
|
Reference in New Issue
Block a user