2023-12-09 20:48:54 +01:00
|
|
|
# /usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Pomodoro timer
|
|
|
|
|
|
|
|
- Writes pomodoro timer to temporary file so statusbar can read it
|
|
|
|
- Notification on session finish
|
|
|
|
- Notification on break finish
|
|
|
|
"""
|
2022-05-04 15:41:07 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import atexit
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from time import sleep
|
|
|
|
from plyer import notification
|
|
|
|
|
2022-10-25 21:30:00 +02:00
|
|
|
|
2022-05-04 15:41:07 +02:00
|
|
|
def clear():
|
2022-10-25 21:30:00 +02:00
|
|
|
os.system('echo -n "" > /tmp/pomo')
|
|
|
|
|
2022-05-04 15:41:07 +02:00
|
|
|
|
|
|
|
atexit.register(clear)
|
|
|
|
|
|
|
|
parser = ArgumentParser()
|
|
|
|
|
2022-10-25 21:30:00 +02:00
|
|
|
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)
|
2022-05-04 15:41:07 +02:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2022-10-25 21:30:00 +02:00
|
|
|
prep_duration = args.prep_duration * 60
|
|
|
|
work_duration = args.work_duration * 60
|
2022-05-04 15:41:07 +02:00
|
|
|
break_duration = args.break_duration * 60
|
2022-05-20 00:37:29 +02:00
|
|
|
repeats = args.repeats
|
|
|
|
|
2022-10-25 21:30:00 +02:00
|
|
|
|
2023-06-14 21:16:39 +02:00
|
|
|
def make_countdown(color="#000000"):
|
2022-10-25 21:30:00 +02:00
|
|
|
def countdown(duration):
|
|
|
|
while duration != 0:
|
|
|
|
mins = duration // 60
|
|
|
|
secs = duration % 60
|
|
|
|
# os.system('echo -n "{:s} {:02d}:{:02d} \x01" > /tmp/pomo'.format(color, mins, secs))
|
2023-06-14 21:16:39 +02:00
|
|
|
os.system(
|
|
|
|
'echo -n "<fc={:s}> {:02d}:{:02d} </fc>" > /tmp/pomo'.format(color, mins, secs))
|
2022-10-25 21:30:00 +02:00
|
|
|
sleep(1)
|
|
|
|
duration -= 1
|
|
|
|
return countdown
|
|
|
|
|
|
|
|
|
2023-06-14 21:16:39 +02:00
|
|
|
prep_countdown = make_countdown("#0000aa")
|
|
|
|
work_countdown = make_countdown("#aa0000")
|
|
|
|
break_countdown = make_countdown("#00bb00")
|
2022-05-20 00:37:29 +02:00
|
|
|
|
|
|
|
prep_countdown(prep_duration)
|
|
|
|
|
2022-10-25 21:30:00 +02:00
|
|
|
while repeats != 0:
|
|
|
|
notification.notify(title="Get started")
|
|
|
|
work_countdown(work_duration)
|
|
|
|
if break_duration != 0:
|
|
|
|
notification.notify(title="Time for a break")
|
|
|
|
break_countdown(break_duration)
|
|
|
|
notification.notify(title="Break is over, back to work")
|
|
|
|
repeats -= 1
|