Last active
December 11, 2015 06:58
-
-
Save smutch/4562690 to your computer and use it in GitHub Desktop.
Present a popup/popups to remind me to leave...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Present a popup/popups to remind me to leave... | |
Usage: | |
leavein <time> | |
Format: | |
<time> should be given as e.g. 1h20m or 30m | |
""" | |
# Attributions: | |
# The time string parser is taken from http://stackoverflow.com/a/3680376 | |
# (jathanism). | |
import sys, re, os | |
from time import sleep | |
from docopt import docopt | |
from pync import Notifier | |
from termcolor import cprint | |
__author__ = "Simon Mutch" | |
__date__ = "18 Jan 2013" | |
PATTERN = r'(?:(?P<hours>\d+)h)?(?:(?P<minutes>\d+)m)?' | |
PRE_WARN_TIME = 300 #s | |
minsec = re.compile(PATTERN) | |
def parse(s, pat=minsec): | |
return pat.match(s).groupdict() | |
if __name__ == '__main__': | |
args = docopt(__doc__, argv=sys.argv[1:], help=True, version="0.1") | |
time = parse(args["<time>"]) | |
for key in time.iterkeys(): | |
if time[key] is None: | |
time[key] = 0 | |
seconds = int(time["hours"])*60*60 + int(time["minutes"])*60 | |
cprint("Leave in %d hours, %d minutes (= %d sec)" % (int(time["hours"]), | |
int(time["minutes"]), | |
seconds), color='blue') | |
if seconds>(PRE_WARN_TIME): | |
seconds-=PRE_WARN_TIME | |
sleep(seconds) | |
Notifier.notify('Time to leave in 5 minutes!', title='WARNING', | |
group="leavein") | |
sleep(seconds) | |
Notifier.remove("leavein") | |
Notifier.notify('Go go go...', execute='say "Time to leave now!"', | |
title='WARNING', group="leavein") | |
cprint("...Time to leave!", color="red") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment