Skip to content

Instantly share code, notes, and snippets.

@sandeepraju
Last active February 1, 2016 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeepraju/6b14771fc797017a3d62 to your computer and use it in GitHub Desktop.
Save sandeepraju/6b14771fc797017a3d62 to your computer and use it in GitHub Desktop.
getting more work done.
import subprocess
import math
import time
from datetime import datetime, timedelta
def pomodoro(target, duration):
counter = 0
start = datetime.now()
end = start + timedelta(minutes=duration)
notification_times = (0, 60*5, 60*10, 60*15, 60*20)
counter_limit = 60 * duration
while counter < counter_limit:
timedel = (end - datetime.now())
minutes_remaining = int(math.ceil(timedel.seconds / 60.0))
if counter in notification_times:
message = 'Time remaining: %s minute%s' % (minutes_remaining, '' if minutes_remaining == 1 else 's')
print message
subprocess.Popen(['notify-send', 'Pomodoro Timer', message])
time.sleep(1)
counter += 1
message = 'Time up!'
print message
subprocess.Popen(['notify-send', 'Pomodoro Timer', message])
with open('pomodoro.txt', 'a') as f:
f.write('%s|%s|%s\n' % (str(start), duration, target))
def main():
target = raw_input('Target: ').strip()
if target:
pomodoro(target, 25)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment