From b54fcdd646594997324b56854642daaa0d798151 Mon Sep 17 00:00:00 2001 From: Von Random Date: Mon, 22 May 2017 17:11:36 +0300 Subject: [PATCH] get rid of -o feature, notify on start, wrap the whole thing in the main() function --- eyewatch.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/eyewatch.py b/eyewatch.py index d26f2a4..6263d2a 100755 --- a/eyewatch.py +++ b/eyewatch.py @@ -28,13 +28,6 @@ def parse_args(sys_args): help=('run in foreground, showing notification every TIMER seconds ' '(this is default, with TIMER = 600)') ) - p.add_argument( - '-o', - '--once', - action='store_true', - default=False, - help='show notification once and exit' - ) p.add_argument( '-i', '--icon', @@ -49,27 +42,24 @@ def get_random_message(message_list): return message_list[random_value] -def show_notification(notification, icon): - text = get_random_message(MESSAGES) - print('[' + strftime('%H:%M:%S') + '] ' + text) - if icon is not None: - notification.update(TITLE, text, icon) - else: - notification.update(TITLE, text) +def show_notification(notification, text=None, icon=None): + notification.update(TITLE, text, icon) notification.set_urgency(URGENCY) notification.show() -if __name__ == '__main__': +def main(): args = parse_args(argv[1:]) Notify.init(argv[0]) notification = Notify.Notification.new(summary=TITLE) - if args.once: - show_notification(notification, args.icon) - else: - while True: - sleep(int(args.timer)) - show_notification(notification, args.icon) + show_notification(notification, 'Eyewatch daemon started!', args.icon) + while True: + sleep(int(args.timer)) + text = get_random_message(MESSAGES) + show_notification(notification, text, args.icon) Notify.uninit() + +if __name__ == '__main__': + main()