Skip to content

Instantly share code, notes, and snippets.

@cstrap
Forked from vrde/pymodoro.py
Created May 9, 2012 16:25
Show Gist options
  • Save cstrap/2646213 to your computer and use it in GitHub Desktop.
Save cstrap/2646213 to your computer and use it in GitHub Desktop.
simple pomodoro implementation with pynotify
import pynotify
from time import sleep
def mins_to_secs(ms):
return map(lambda x: x * 60, ms)
class Pymodoro(object):
POMODORO_TIME = 25 * 60
POMODORO_CHECKPOINTS = mins_to_secs([25, 15, 10, 5, 3, 1]) + range(10)
REST_TIME = 5 * 60
REST_CHECKPOINTS = mins_to_secs([5, 3, 1]) + range(30)
LONG_REST_TIME = 15 * 60
LONG_REST_CHECKPOINTS = mins_to_secs([15, 10, 5, 3, 1]) + range(30)
def __init__(self):
self.n = pynotify.Notification('Pymodoro')
def go(self):
while True:
self.cycle('Pomodoro (1/4)', self.POMODORO_TIME, self.POMODORO_CHECKPOINTS)
self.cycle('Rest', self.REST_TIME, self.REST_CHECKPOINTS)
self.cycle('Pomodoro (2/4)', self.POMODORO_TIME, self.POMODORO_CHECKPOINTS)
self.cycle('Rest', self.REST_TIME, self.REST_CHECKPOINTS)
self.cycle('Pomodoro (3/4)', self.POMODORO_TIME, self.POMODORO_CHECKPOINTS)
self.cycle('Rest', self.REST_TIME, self.REST_CHECKPOINTS)
self.cycle('Pomodoro (4/4)', self.POMODORO_TIME, self.POMODORO_CHECKPOINTS)
self.cycle('Long Rest', self.LONG_REST_TIME, self.LONG_REST_CHECKPOINTS)
def update(self, title, msg, timeout=pynotify.EXPIRES_DEFAULT):
self.n.update(title, msg)
self.n.set_timeout(timeout * 1000)
self.n.show()
def cycle(self, title, how_much, hot_seconds):
while how_much:
if how_much in hot_seconds:
if how_much >= 60:
self.update(title, 'You have {0} minutes left.'.format(how_much / 60))
else:
self.update(title, 'You have {0} seconds left.'.format(how_much), timeout=0)
sleep(1)
how_much -= 1
def main():
pynotify.init("Pymodoro")
pymodoro = Pymodoro()
pymodoro.go()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment