83 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
#!/usr/bin/env python3
 | 
						|
# vim: set filetype=python:
 | 
						|
"""
 | 
						|
Pomodoro timer
 | 
						|
 | 
						|
- Writes pomodoro timer to temporary file so statusbar can read it
 | 
						|
- Notification on session finish
 | 
						|
- Notification on break finish
 | 
						|
"""
 | 
						|
 | 
						|
import os
 | 
						|
import atexit
 | 
						|
from argparse import ArgumentParser
 | 
						|
from time import sleep
 | 
						|
from plyer import notification
 | 
						|
 | 
						|
 | 
						|
@atexit.register
 | 
						|
def clear():
 | 
						|
    if os.path.exists('/home/h/.local/share/pomo'):
 | 
						|
        os.remove('/home/h/.local/share/pomo')
 | 
						|
 | 
						|
def format_mins_secs(mins, secs):
 | 
						|
    return f"{mins:02d}:{secs:02d}"
 | 
						|
 | 
						|
 | 
						|
def make_countdown():
 | 
						|
    def countdown(duration):
 | 
						|
        while duration != 0:
 | 
						|
            mins = duration // 60
 | 
						|
            secs = duration % 60
 | 
						|
            time_str = format_mins_secs(mins, secs)
 | 
						|
            os.system(f'echo -n "{time_str}" > /home/h/.local/share/pomo')
 | 
						|
            sleep(1)
 | 
						|
            duration -= 1
 | 
						|
    return countdown
 | 
						|
 | 
						|
 | 
						|
def main(args):
 | 
						|
    prep_duration = args.prep_duration * 60
 | 
						|
    work_duration = args.work_duration * 60
 | 
						|
    break_duration = args.break_duration * 60
 | 
						|
    repeats = args.repeats
 | 
						|
 | 
						|
    prep_countdown = make_countdown()
 | 
						|
    work_countdown = make_countdown()
 | 
						|
    break_countdown = make_countdown()
 | 
						|
 | 
						|
    prep_countdown(prep_duration)
 | 
						|
 | 
						|
    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
 | 
						|
 | 
						|
 | 
						|
def handle_signal(signal, frame):
 | 
						|
    # Wait for clear to finish
 | 
						|
    clear()
 | 
						|
    print('Exiting')
 | 
						|
    exit(0)
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
 | 
						|
    parser = ArgumentParser()
 | 
						|
    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)
 | 
						|
    parser.add_argument('-c', '--clear', action='store_true',
 | 
						|
                        help='Clear timer')
 | 
						|
 | 
						|
    args = parser.parse_args()
 | 
						|
 | 
						|
    main(args)
 |