Update pomodoro script

master
Hektor Misplon 2022-10-25 21:30:00 +02:00
parent cac2e1a74e
commit 64d92013c1
1 changed files with 35 additions and 25 deletions

View File

@ -13,17 +13,23 @@ from argparse import ArgumentParser
from time import sleep from time import sleep
from plyer import notification from plyer import notification
def clear(): def clear():
os.system('echo -n "" > /tmp/pomo') os.system('echo -n "" > /tmp/pomo')
atexit.register(clear) atexit.register(clear)
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('-p', '--prep-duration', type=int, help='Preparation duration of a session', default=0) parser.add_argument('-p', '--prep-duration', type=int,
parser.add_argument('-w', '--work-duration', type=int, help='Duration of a session', default=25) help='Pre session duration', default=0)
parser.add_argument('-b', '--break-duration', type=int, help='Duration of a break', default=5) parser.add_argument('-w', '--work-duration', type=int,
parser.add_argument('-r', '--repeats', type=int, help='Numer of sessions', default=1) help='Session duration', default=25)
parser.add_argument('-b', '--break-duration', type=int,
help='Break duration', default=5)
parser.add_argument('-r', '--repeats', type=int,
help='Numer of sessions', default=1)
args = parser.parse_args() args = parser.parse_args()
@ -32,16 +38,19 @@ work_duration = args.work_duration * 60
break_duration = args.break_duration * 60 break_duration = args.break_duration * 60
repeats = args.repeats repeats = args.repeats
def make_countdown(color): def make_countdown(color):
def countdown(duration): def countdown(duration):
while duration != 0: while duration != 0:
mins = duration // 60 mins = duration // 60
secs = duration % 60 secs = duration % 60
os.system('echo -n "{:s} {:02d}:{:02d} \x01" > /tmp/pomo'.format(color, mins, secs)) # os.system('echo -n "{:s} {:02d}:{:02d} \x01" > /tmp/pomo'.format(color, mins, secs))
os.system('echo -n "{:02d}:{:02d}" > /tmp/pomo'.format(mins, secs))
sleep(1) sleep(1)
duration -= 1 duration -= 1
return countdown return countdown
prep_countdown = make_countdown("\x01") prep_countdown = make_countdown("\x01")
work_countdown = make_countdown("\x03") work_countdown = make_countdown("\x03")
break_countdown = make_countdown("\x02") break_countdown = make_countdown("\x02")
@ -51,7 +60,8 @@ prep_countdown(prep_duration)
while repeats != 0: while repeats != 0:
notification.notify(title="Get started") notification.notify(title="Get started")
work_countdown(work_duration) work_countdown(work_duration)
if break_duration != 0:
notification.notify(title="Time for a break") notification.notify(title="Time for a break")
break_countdown(break_duration) break_countdown(break_duration)
notification.notify(title="Break is over, set a new timer") notification.notify(title="Break is over, back to work")
repeats -= 1 repeats -= 1