aboutsummaryrefslogtreecommitdiff
path: root/Scripts/.local/scripts/timer
blob: 84ee0954223eb3e2781514c0bf605f827dbabdbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
from time import sleep
from sys import argv
from os import system
from subprocess import run

def speak(text: str, volume=100, word_gap=20):
    system(f'espeak -a {volume} -g {word_gap} -k 20 "{text}"')

def alert(text:str):
    run(["notify-send", text])

def beep(time):
    system(f"play -q -n synth {time} sin 880")

if __name__ == '__main__':
    work_duration = 50
    if (len(argv) > 1):
        work_duration = int(argv[1])

    gap_duration = 10
    if (len(argv) > 2):
        gap_duration = int(argv[2])

    beep(0.1)
    alert(f"Starting timer with work={work_duration}, gap={gap_duration}")

    for i in range(1, work_duration + 1):
        sleep(60)
        if i == 0:
            alert(f"Work time has finished")
        elif i % 10 == 0:
            alert(f"{work_duration - i} minutes of study time left")

    beep(1)
    alert("You can take a break now!")
    for i in range(1, gap_duration + 1):
        sleep(60)
        if i == 0:
            alert(f"Gap time has finished")
            beep(1)
        elif i % 10 == 0:
            alert(f"{gap_duration - i} minutes of gap time left")
    beep(1)