random script dump
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eyewatch.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. from argparse import ArgumentParser
  3. from random import randint
  4. from sys import argv
  5. from time import sleep, strftime
  6. import gi
  7. gi.require_version('Notify', '0.7')
  8. from gi.repository import Notify
  9. URGENCY = 0
  10. TITLE = 'EYE WATCH'
  11. MESSAGES = (
  12. 'do some blinking',
  13. 'roll your eyes a few times',
  14. 'look at a distant object',
  15. 'close your eyes tightly for a few seconds',
  16. 'move your eyes sideways'
  17. )
  18. def parse_args():
  19. desc = 'display a reminder to take a short break and do some eye practice'
  20. parser = ArgumentParser(description=desc)
  21. parser.add_argument(
  22. '-t',
  23. '--timer',
  24. default='600',
  25. help=('run in foreground, showing notification every TIMER seconds '
  26. '(this is default, with TIMER = 600)')
  27. )
  28. parser.add_argument(
  29. '-i',
  30. '--icon',
  31. help='show ICON alongside the message'
  32. )
  33. return parser.parse_args()
  34. def get_random_message(message_list):
  35. list_len = len(message_list)
  36. random_value = randint(0, list_len - 1)
  37. return message_list[random_value]
  38. def show_notification(notification, text=None, icon=None):
  39. notification.update(TITLE, text, icon)
  40. notification.set_urgency(URGENCY)
  41. notification.show()
  42. def main():
  43. args = parse_args()
  44. Notify.init(argv[0])
  45. notification = Notify.Notification.new(summary=TITLE)
  46. show_notification(notification, 'Eyewatch daemon started!', args.icon)
  47. while True:
  48. sleep(int(args.timer))
  49. text = get_random_message(MESSAGES)
  50. show_notification(notification, text, args.icon)
  51. Notify.uninit()
  52. if __name__ == '__main__':
  53. main()