Skip to content

Instantly share code, notes, and snippets.

@rhwlo
Created February 22, 2016 20:28
Show Gist options
  • Save rhwlo/8adc4002b80b2b498c7d to your computer and use it in GitHub Desktop.
Save rhwlo/8adc4002b80b2b498c7d to your computer and use it in GitHub Desktop.
friendly reminders on Linux
#!/usr/bin/env python3
#
# alias remind-me="$HOME/bin/remind_me.py"
from sys import argv, exit, stderr
import subprocess
import time
USAGE_STRING = """
usage: remind-me @time "your message goes here"
"""
try:
from gi.repository import Notify
except ImportError:
print("""
Library gi.repository not found. Install PyGObject for your distro from here:
https://wiki.gnome.org/action/show/Projects/PyGObject#Downloads""",
file=stderr)
exit(2)
def usage():
print(USAGE_STRING, file=stderr)
exit(1)
# there's probably a better way to get the date, but this one works, so ...
try:
scheduled_time_string = argv[1]
scheduled_time = float(subprocess.check_output(["date", "+%s", "--date", scheduled_time_string]))
except IndexError:
usage()
except subprocess.CalledProcessError:
print("GNU `date` is good at parsing datestrings, but it couldn't make heads or tails of {}".format(argv[1]),
file=sys.stderr)
exit(1)
try:
message = argv[2]
except IndexError:
print("No message given, but the reminder will fire off. Hopefully you remember what you were thinking of!",
file=sys.stderr)
message = "[no message]"
delta = scheduled_time - time.time()
if delta < 0:
print("Time {} is in the past.".format(time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime(scheduled_time))))
exit(3)
time.sleep(delta)
Notify.init("reminder")
notification = Notify.Notification.new("reminder", message, "face-monkey")
notification.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment