get rid of -o feature, notify on start, wrap the whole thing in the main() function

This commit is contained in:
Von Random 2017-05-22 17:11:36 +03:00
parent bc7d13bb48
commit b54fcdd646

View file

@ -28,13 +28,6 @@ def parse_args(sys_args):
help=('run in foreground, showing notification every TIMER seconds ' help=('run in foreground, showing notification every TIMER seconds '
'(this is default, with TIMER = 600)') '(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( p.add_argument(
'-i', '-i',
'--icon', '--icon',
@ -49,27 +42,24 @@ def get_random_message(message_list):
return message_list[random_value] return message_list[random_value]
def show_notification(notification, icon): def show_notification(notification, text=None, icon=None):
text = get_random_message(MESSAGES) notification.update(TITLE, text, icon)
print('[' + strftime('%H:%M:%S') + '] ' + text)
if icon is not None:
notification.update(TITLE, text, icon)
else:
notification.update(TITLE, text)
notification.set_urgency(URGENCY) notification.set_urgency(URGENCY)
notification.show() notification.show()
if __name__ == '__main__': def main():
args = parse_args(argv[1:]) args = parse_args(argv[1:])
Notify.init(argv[0]) Notify.init(argv[0])
notification = Notify.Notification.new(summary=TITLE) notification = Notify.Notification.new(summary=TITLE)
if args.once: show_notification(notification, 'Eyewatch daemon started!', args.icon)
show_notification(notification, args.icon) while True:
else: sleep(int(args.timer))
while True: text = get_random_message(MESSAGES)
sleep(int(args.timer)) show_notification(notification, text, args.icon)
show_notification(notification, args.icon)
Notify.uninit() Notify.uninit()
if __name__ == '__main__':
main()