-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
64 lines (49 loc) · 1.99 KB
/
timer.py
File metadata and controls
64 lines (49 loc) · 1.99 KB
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
import logging
import timer_thread
running_thread = None
def stopCountDown():
if running_thread is not None:
logging.info(running_thread)
global running_thread
running_thread.do_run = False
def countDown(timeToEnd, speaktime, speakinterval):
logging.info("in Countdown:" + str(timeToEnd))
global running_thread
if running_thread is not None:
running_thread.stop()
speakTimeMap = buildMapForSpeakTime(timeToEnd, speaktime)
running_thread = timer_thread.TimerThread(
timeToEnd=timeToEnd, speaktime=speakTimeMap, speakinterval=speakinterval)
running_thread.start()
def buildMapForSpeakTime(timeToEnd, speaktimeList):
# take input list and create dict of time and saying
# calculate time
speakMap = {}
for speakItem in speaktimeList:
timeOfItem = speakItem["time"] # this might say at the 10 minute mark
# find future time for time in list
secondsToTimer = timeInSecondsOfSpeech(timeOfItem, timeToEnd)
secondsToTimerStr = str(secondsToTimer)
print("timeToSpeak=" + secondsToTimerStr)
speakMap[secondsToTimerStr] = {"phrase": speakItem["say"]}
if "parms" in speakItem:
speakMap[secondsToTimerStr]["parms"] = speakItem["parms"]
if "file" in speakItem:
speakMap[secondsToTimerStr]["file"] = speakItem["file"]
return speakMap
def timeInSecondsOfSpeech(timeInMinutes, timeToEnd):
minutes = timeInMinutes
seconds = 0
if ":" in timeInMinutes:
splitTimeInMinutes = timeInMinutes.split(":")
minutes = splitTimeInMinutes[0]
seconds = splitTimeInMinutes[1]
timeInSec = int(minutes) * 60
timeInSec += int(seconds)
return timeToEnd - timeInSec
def buildMapForSpeakInterval(speakIntervalList):
# take input list and create dict of time and saying
speakIntervalMap = {}
for speakItem in speakIntervalList:
speakIntervalMap[speakItem["interval"]] = speakItem["say"]
return speakIntervalMap