Compare commits

...

5 Commits

Author SHA1 Message Date
e424c7ecb6 Merge pull request 'timers-module' (#38) from timers-module into v2.0
Reviewed-on: #38
2021-05-06 04:09:33 +00:00
Alex Orid
c30decd0ef Port Changes 2021-05-06 00:07:53 -04:00
Alex Orid
8c7bc3e56b typo 2021-05-05 18:01:54 -04:00
Alex Orid
988f791a42 Working Version 2021-05-05 18:00:40 -04:00
Alex Orid
7365c2e3ee progress 2021-05-05 14:06:52 -04:00
26 changed files with 232 additions and 100 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ credentials/
stream_sources/chyron.txt
stream_sources/brb.txt
*.log
timers/

View File

@ -26,17 +26,27 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
#print("sending:",user, 16, "!lights hydration")
try:
if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", ""))
thread_.daemon = True
self.threads.append(thread_)
thread_.start()
if self.is_ChannelReward_enabled:
prompt_ = self.get_Phrase(rewardPrompt)
thread_ = threading.Thread(target=self.send_TTS, args=(user, prompt_))
thread_.daemon = True
self.threads.append(thread_)
thread_.start()
try:
if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", ""))
thread_.daemon = True
self.threads.append(thread_)
thread_.start()
except:
if self.is_ChannelReward_enabled:
thread_ = threading.Thread(target=self.send_TTS, args=("", "Silly Nerd Fix The Lights Module"))
thread_.daemon = True
self.threads.append(thread_)
thread_.start()
try:
if self.is_ChannelReward_enabled:
prompt_ = self.get_Phrase(rewardPrompt)
thread_ = threading.Thread(target=self.send_TTS, args=(user, prompt_))
thread_.daemon = True
self.threads.append(thread_)
thread_.start()
except:
pass
except:
pass
@ -46,7 +56,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +72,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -47,7 +47,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -63,7 +63,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_Suggest_Poll(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_Suggest_Poll(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_TTS_Message(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_TTS_Message(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_Workout_Pushups(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_Workout_Pushups(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_Workout_Situps(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_Workout_Situps(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_Workout_Squats(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_Workout_Squats(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -45,7 +45,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -61,7 +61,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -46,7 +46,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -62,7 +62,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -57,7 +57,7 @@ class Command_chyron_v2(AbstractCommand, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -47,7 +47,7 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -107,7 +107,7 @@ class Command_Text_v2(AbstractCommand, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -67,7 +67,7 @@ class Command_tts_v2(AbstractCommand, metaclass=ABCMeta):
# todo need to url-escape command and rest
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest})
#standalone_lights
url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params
url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -83,7 +83,7 @@ class Command_tts_v2(AbstractCommand, metaclass=ABCMeta):
def send_TTS(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -5,7 +5,7 @@ services:
volumes:
- "./:/Praxis/"
ports:
- 6009:6009
- 42010:42010
environment:
- ISDOCKER=cat
standalone_channelrewards:
@ -13,7 +13,7 @@ services:
volumes:
- "./:/Praxis/"
ports:
- 6969:6969
- 42069:42069
environment:
- ISDOCKER=cat
standalone_lights:
@ -21,7 +21,7 @@ services:
volumes:
- "./:/Praxis/"
ports:
- 42069:42069
- 42042:42042
environment:
- ISDOCKER=cat
standalone_tts_core:
@ -29,7 +29,7 @@ services:
volumes:
- "./:/Praxis/"
ports:
- 60809:60809
- 42064:42064
environment:
- ISDOCKER=cat
standalone_websource:
@ -37,7 +37,7 @@ services:
volumes:
- "./:/Praxis/"
ports:
- 5500:5500
- 42088:42088
environment:
- ISDOCKER=cat
standalone_twitchscript:

View File

@ -110,4 +110,4 @@ def exec_reward():
if __name__ == '__main__':
init()
api.run(host='0.0.0.0', port=6969)
api.run(host='0.0.0.0', port=42069)

View File

@ -83,4 +83,4 @@ def exec_command():
if __name__ == '__main__':
init()
api.run(host='0.0.0.0', port=6009)
api.run(host='0.0.0.0', port=42010)

View File

@ -105,7 +105,7 @@ class Discord_Module(discord.Client):
async def is_command(self, word: str) -> bool:
# todo need to url-escape word
clean_param = urlencode({'name': word})
url = "http://standalone_command:6009/api/v1/command?%s" % clean_param
url = "http://standalone_command:42010/api/v1/command?%s" % clean_param
resp = requests.get(url)
return resp.status_code == 200
@ -118,7 +118,7 @@ class Discord_Module(discord.Client):
'rest': rest,
'bonus_data': realMessage})
url = "http://standalone_command:6009/api/v1/exec_command?%s" % params
url = "http://standalone_command:42010/api/v1/exec_command?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -180,7 +180,7 @@ class Discord_Module(discord.Client):
async def exec_tts_sender(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -302,5 +302,5 @@ def exec_lights():
if __name__ == "__main__":
init()
api.run(host='0.0.0.0', port=42069)
api.run(host='0.0.0.0', port=42042)
#testModule.raveMode()

View File

@ -42,4 +42,4 @@ def makeRequest():
if __name__ == "__main__":
init()
api.run(host='0.0.0.0', port=6009)
api.run(host='0.0.0.0', port=42010)

View File

@ -51,4 +51,4 @@ def tts_send_text():
if __name__ == '__main__':
#send_text("","Blah Blah Blah")
#init()
api.run(host='0.0.0.0', port=60809)
api.run(host='0.0.0.0', port=42064)

View File

@ -171,7 +171,7 @@ class Twitch_Pubsub():
clean_param = urlencode({'reward_name': rewardName, 'reward_type':rewardType})
print(rewardName, rewardType)
#standalone_channelrewards
url = "http://standalone_channelrewards:6969/api/v1/reward?%s" % clean_param
url = "http://standalone_channelrewards:42069/api/v1/reward?%s" % clean_param
resp = requests.get(url)
return resp.status_code == 200
@ -186,7 +186,7 @@ class Twitch_Pubsub():
'bonus_data': realMessage})
#standalone_channelrewards
url = "http://standalone_channelrewards:6969/api/v1/exec_reward?%s" % params
url = "http://standalone_channelrewards:42069/api/v1/exec_reward?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -83,7 +83,7 @@ class Twitch_Module():
def is_command(self, word: str) -> bool:
# todo need to url-escape word
clean_param = urlencode({'name': word})
url = "http://standalone_command:6009/api/v1/command?%s" % clean_param
url = "http://standalone_command:42010/api/v1/command?%s" % clean_param
resp = requests.get(url)
return resp.status_code == 200
@ -96,7 +96,7 @@ class Twitch_Module():
'rest': rest,
'bonus_data': realMessage})
url = "http://standalone_command:6009/api/v1/exec_command?%s" % params
url = "http://standalone_command:42010/api/v1/exec_command?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)
@ -134,7 +134,7 @@ class Twitch_Module():
def exec_tts_sender(self, username, message):
params = urlencode({'tts_sender': username, 'tts_text': message})
#standalone_tts_core
url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params
url = "http://standalone_tts_core:42064/api/v1/tts/send_text?%s" % params
resp = requests.get(url)
if resp.status_code == 200:
print("Got the following message: %s" % resp.text)

View File

@ -16,7 +16,13 @@ from cooldowns import Cooldown_Module
import utilities_script as utility
import chyron_module
import timers_module
import os
import praxis_logging
praxis_logger_obj = praxis_logging.praxis_logger()
praxis_logger_obj.init(os.path.basename(__file__))
praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__))
api:Flask = Flask(__name__)
api.config["DEBUG"] = True
@ -40,13 +46,21 @@ def textSource_tempText(file_name):
tempModule = tempText_Module.tempText_Module()
return tempModule.getTempTextFile(file_name)
@api.route('/timer/<timer_name>/')
def textSource_timers(timer_name):
#print("trying file: ", filename)
#tempModule = tempText_Module.tempText_Module()
#tempModule.getTempTextFile(filename)
return "Coming Soon"
@api.route('/timer/status/<timer_name>/')
def textSource_timerStatus(timer_name):
tempModule = timers_module.Timers_Module()
result = tempModule.checkTimerStatus_fromFiles(timer_name)
returnString = "Timer %s is %s" % (timer_name, result)
return returnString
@api.route('/timer/time/<timer_name>/')
def textSource_timerTime(timer_name):
tempModule = timers_module.Timers_Module()
result = tempModule.checkTime_fromFiles(timer_name)
if result is None: result = ""
returnString = result
return returnString
if __name__ == "__main__":
init()
api.run(host="0.0.0.0", port = 5500)
api.run(host="0.0.0.0", port = 42088)

View File

@ -1,52 +1,151 @@
import os
import json
from praxis_logging import praxis_logger
import time
import datetime
import utilities_script as utility
import importlib
import importlib.util
import sys
import inspect
class timer():
def __init__(self, name, startTime, endTime, trigger, trigger_exec, tempTimer = True):
def __init__(self,
name,
startTime = datetime.datetime.now,
endTime = datetime.datetime.now,
trigger = "",
trigger_exec = "",
timerFormat = "%Y-%m-%d %H:%M:%S.%f",
tempTimer = True):
self.name = name
self.startTime = startTime
self.endTime = endTime
self.trigger = trigger
self.trigger_exec = trigger_exec
self.timerFormat = timerFormat
self.tempTimer = tempTimer # If enabled this will cause the Timer to be deleted upon shutdown or startup
class Timers_Module():
def __init__(self):
super().__init__()
self.timersList = []
self.timersList = {}
def main(self):
self.createTimer()
self.createTimer("test_timer", seconds=15)
#self.createTimer("mega_test_timer", hours=20, seconds=10)
#self.updateTimersList()
#for t in self.timersList:
#print(t)
#while True:
#for t in self.timersList:
#print(t)
#print(self.checkTimerStatus_fromFiles("test_timer"))
#print(self.checkTimerStatus_fromFiles("test_timer_2"))
#time.sleep(0.5)
def updateTimersList(self):
pass
dic = {}
implementations = self.get_implementations_dir()
for dirName, subdirList, fileList in os.walk(implementations):
for file in fileList:
print(file)
name, startTime, endTime, trigger, trigger_exec, timerFormat, tempTimer = self.readFile(file)
newTimer = timer(
name,
datetime.datetime.strptime(startTime, timerFormat),
datetime.datetime.strptime(endTime, timerFormat),
trigger,
trigger_exec,
utility.strToBool(tempTimer))
def createTimer(self, days=0, hours=0, minutes=0, seconds=0, microseconds=0, trigger="", trigger_exec="", tempTimer=True):
temp = datetime.datetime.now()
targetTime = temp + datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)
self.timersList[newTimer.name] = newTimer
return dic
newTimer= timer()
newTimer.startTime = temp
newTimer.endTime = targetTime
newTimer.trigger = trigger
newTimer.trigger_exec = trigger_exec
newTimer.tempTimer = tempTimer
self.timersList.append(newTimer)
def get_base_dir(self) -> str:
cwd = os.getcwd()
split = os.path.split(cwd)
current = split[len(split) - 1]
if current == 'timers':
return self.check_dir(cwd)
elif current == 'Praxis_Bot' or current == 'Praxis':
return self.check_dir(os.path.join(cwd, "timers"))
else:
print("could not find working directory for Praxis_Bot/timers")
raise Exception
def checkTimer(self, name):
def get_implementations_dir(self) -> str:
return self.check_dir(os.path.join(self.get_base_dir()))
name, startTime, endTime, trigger, trigger_exec, tempTimer = self.readFile(name)
if endTime < datetime.datetime.now():
print("do timer thing")
self.TIMER_EXEC(name, startTime, endTime, trigger, trigger_exec, tempTimer)
def check_dir(self, path: str) -> str:
if not os.path.exists(path):
os.mkdir(path, 0x777)
return path
def createTimer(self, name, days=0, hours=0, minutes=0, seconds=0, microseconds=0, trigger="", trigger_exec="", timerFormat='%Y-%m-%d %H:%M:%S.%f', tempTimer=True):
startTime = datetime.datetime.now()
targetTime = startTime + datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)
newTimer= timer(name, startTime, targetTime, trigger, trigger_exec, timerFormat, tempTimer)
self.timersList[newTimer.name] = newTimer
self.makeFile(newTimer)
def checkTimerStatus_fromFiles(self, name):
try:
if name is not None:
name, startTime, endTime, trigger, trigger_exec, timerFormat, tempTimer = self.readFile(name+".json")
if datetime.datetime.strptime(endTime, timerFormat) < datetime.datetime.now():
#print("do timer thing")
#self.TIMER_EXEC(name, datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S.%f'), datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S.%f'), trigger, trigger_exec, utility.strToBool(tempTimer))
return True
else:
return False
else:
return False
except:
return None
def checkTime_fromFiles(self, name):
try:
name, startTime, endTime, trigger, trigger_exec, timerFormat, tempTimer = self.readFile(name+".json")
if name is not None:
endT = datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S.%f')
if endT.timestamp() < datetime.datetime.now().timestamp():
print("do timer thing")
endT = datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S.%f')
curTime = datetime.datetime.now()
#curTime = datetime.datetime.strptime(curTime, '%Y-%m-%d %H:%M:%S.%f')
result = endT - datetime.timedelta(days=curTime.day, hours=curTime.hour, minutes=curTime.minute, seconds=curTime.second, microseconds=curTime.microsecond)
print(type(result))
#self.TIMER_EXEC(name, datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S.%f'), datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S.%f'), trigger, trigger_exec, utility.strToBool(tempTimer))
fixedEndTime = datetime.datetime.strftime(result, '%M:%S')
return str("Timer Done")
else:
endT = datetime.datetime.strptime(endTime, '%Y-%m-%d %H:%M:%S.%f')
curTime = str(datetime.datetime.now())
curTime = datetime.datetime.strptime(curTime, '%Y-%m-%d %H:%M:%S.%f')
result = endT - datetime.timedelta(days=curTime.day, hours=curTime.hour, minutes=curTime.minute, seconds=curTime.second, microseconds=curTime.microsecond)
fixedEndTime = datetime.datetime.strftime(result, '%M:%S')
#fixedTimeDelta = fixedEndTime - fixedCurTime
#praxis_logger.log(str(timeDelta))
return str(fixedEndTime)
else:
return None
except:
return None
def deleteTimer(self, name):
self.deleteFile(name)
try:
self.deleteFile(name+".json")
except:
print("Deletion Error")
self.timersList.pop(name)
def TIMER_EXEC(self, name, startTime, endTime, trigger, trigger_exec, tempTimer):
@ -57,30 +156,31 @@ class Timers_Module():
self.deleteTimer(name)
def makeFile(self, name, startTime, endTime, trigger, trigger_exec, tempTimer = True):
dir = utility.get_dir("stream_sources/timers")
def makeFile(self, timer_obj:timer):
dir = utility.get_dir("timers")
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
relative_path = name + ".json"
real_file_path = os.path.join(script_dir, relative_path)
with open(real_file_path, 'rw') as cred_r:
data = json.load(cred_r)
data['name'] = name
data['startTime'] = startTime
data['endTime'] = endTime
data['trigger'] = trigger
data['trigger_exec'] = trigger_exec
data['tempTimer'] = tempTimer
relative_path = timer_obj.name + ".json"
real_file_path = os.path.join(script_dir, dir, relative_path)
with open(real_file_path, 'w') as cred_w:
json.dump(data, cred_w, indent=2)
#data = json.load(timer_obj)
dic = {}
dic['name'] = timer_obj.name
dic['startTime'] = str(timer_obj.startTime)
dic['endTime'] = str(timer_obj.endTime)
dic['trigger'] = timer_obj.trigger
dic['trigger_exec'] = timer_obj.trigger_exec
dic['timerFormat'] = timer_obj.timerFormat
dic['tempTimer'] = str(timer_obj.tempTimer)
json.dump(dic, cred_w, indent=2)
def readFile(self, name):
dir = utility.get_dir("stream_sources/timers")
dir = utility.get_dir("timers")
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
relative_path = name + ".json"
real_file_path = os.path.join(script_dir, relative_path)
relative_path = name #+ ".json"
real_file_path = os.path.join(script_dir, dir, relative_path)
startTime, endTime, trigger, tempTimer = None
with open(real_file_path, 'r') as cred_r:
data = json.load(cred_r)
name = data['name']
@ -88,14 +188,15 @@ class Timers_Module():
endTime = data['endTime']
trigger = data['trigger']
trigger_exec = data['trigger_exec']
timerFormat = data['timerFormat']
tempTimer = data['tempTimer']
return name, startTime, endTime, trigger, trigger_exec, tempTimer
return name, startTime, endTime, trigger, trigger_exec, timerFormat, tempTimer
def deleteFile(self, name):
dir = utility.get_dir("stream_sources/timers")
dir = utility.get_dir("timers")
script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in
relative_path = name + ".json"
real_file_path = os.path.join(script_dir, relative_path)
relative_path = name #+ ".json"
real_file_path = os.path.join(script_dir, dir, relative_path)
os.remove(real_file_path)

View File

@ -40,6 +40,12 @@ def rescale_value(value, min, max):
#print("got ", returnValue)
return returnValue
def strToBool(stringToTest):
if stringToTest == "True":
return True
else:
return False
def get_dir(selected_dir):
"""
Checks for the tts directory, and will create it if it does not exist