Refactor 'pomo' script

master
Hektor Misplon 2023-12-09 21:19:41 +01:00
parent 41568b9bc6
commit 07eec68706
1 changed files with 44 additions and 36 deletions

View File

@ -1,4 +1,5 @@
# /usr/bin/env python3 #!/usr/bin/env python3
# vim: set filetype=python:
""" """
Pomodoro timer Pomodoro timer
@ -18,47 +19,37 @@ def clear():
os.system('echo -n "" > /tmp/pomo') os.system('echo -n "" > /tmp/pomo')
atexit.register(clear) def format_mins_secs(mins, secs):
return f"{mins:02d}:{secs:02d}"
parser = ArgumentParser()
parser.add_argument('-p', '--prep-duration', type=int,
help='Pre session duration', default=0)
parser.add_argument('-w', '--work-duration', type=int,
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()
prep_duration = args.prep_duration * 60
work_duration = args.work_duration * 60
break_duration = args.break_duration * 60
repeats = args.repeats
def make_countdown(color="#000000"): def make_countdown():
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)) time_str = format_mins_secs(mins, secs)
os.system( os.system(f'echo -n "{time_str}" > /tmp/pomo')
'echo -n "<fc={:s}> {:02d}:{:02d} </fc>" > /tmp/pomo'.format(color, mins, secs))
sleep(1) sleep(1)
duration -= 1 duration -= 1
return countdown return countdown
prep_countdown = make_countdown("#0000aa") def main(args):
work_countdown = make_countdown("#aa0000") atexit.register(clear)
break_countdown = make_countdown("#00bb00")
prep_countdown(prep_duration) prep_duration = args.prep_duration * 60
work_duration = args.work_duration * 60
break_duration = args.break_duration * 60
repeats = args.repeats
while repeats != 0: prep_countdown = make_countdown()
work_countdown = make_countdown()
break_countdown = make_countdown()
prep_countdown(prep_duration)
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: if break_duration != 0:
@ -66,3 +57,20 @@ while repeats != 0:
break_countdown(break_duration) break_countdown(break_duration)
notification.notify(title="Break is over, back to work") notification.notify(title="Break is over, back to work")
repeats -= 1 repeats -= 1
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-p', '--prep-duration', type=int,
help='Pre session duration', default=0)
parser.add_argument('-w', '--work-duration', type=int,
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()
main(args)