-
Notifications
You must be signed in to change notification settings - Fork 0
/
remind
executable file
·82 lines (72 loc) · 2.49 KB
/
remind
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/local/bin/python3
import argparse
import math
import random
import signal
import subprocess
import sys
import threading
import time
VOICE = random.choice(['Daniel', 'Fiona', 'Karen', 'Samantha', 'Tessa'])
DURATION = 10
def say(message):
spawn_subprocess('say', '-v', VOICE, '[[volm 0.5]]', message)
def spawn_subprocess(*args):
def target():
subprocess.run(args)
threading.Thread(target=target).start()
class PauseException(Exception):
pass
class StopException(Exception):
pass
def signal_handler(signum, frame):
raise PauseException()
def signal_handler2(signum, frame):
raise StopException()
if __name__ == '__main__':
try:
signal.signal(signal.SIGTSTP, signal_handler)
signal.signal(signal.SIGINT, signal_handler2)
parser = argparse.ArgumentParser(description='Count down the time.')
parser.add_argument('duration', type=int)
args = parser.parse_args()
start = time.time()
end = start + args.duration * 60
paused = None
said_finished = False
while True:
try:
now = time.time()
print('\x1b[2K', end='\r')
if paused is None:
if now < end:
left = end - now
hours = int(math.ceil(left) / 3600)
minutes = int(math.ceil(left) % 3600 / 60)
seconds = int(math.ceil(left) % 60)
if hours > 0:
print(hours, end=':')
if hours > 0:
print('{0:02d}'.format(minutes), end=':')
elif minutes > 0:
print(minutes, end=':')
print('{0:02d}'.format(seconds))
time.sleep(left)
else:
if not said_finished:
said_finished = True
while True:
spawn_subprocess('osascript', '-e', 'beep')
time.sleep(1.5)
else:
print('Paused')
while True:
time.sleep(3600)
except PauseException:
if paused is None:
paused = time.time()
else:
end = time.time() + (end - paused)
paused = None
except StopException:
pass