fixing recursion issues
This commit is contained in:
parent
a3d8a3543d
commit
b457999d3d
15
.vscode/launch.json
vendored
15
.vscode/launch.json
vendored
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Python: Aktuelle Datei",
|
|
||||||
"type": "python",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${file}",
|
|
||||||
"console": "integratedTerminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,10 +1,13 @@
|
|||||||
import requests
|
import requests
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
class WeatherFetch():
|
class WeatherFetch():
|
||||||
def __init__(self, key):
|
def __init__(self, key):
|
||||||
self.last_fetch = datetime.datetime.fromtimestamp(0)
|
self.last_fetch = datetime.datetime.fromtimestamp(0)
|
||||||
self.last_weather = ""
|
self.last_weather = ""
|
||||||
|
self.calls = 0
|
||||||
|
|
||||||
self.url = "https://api.openweathermap.org/data/2.5/onecall?"
|
self.url = "https://api.openweathermap.org/data/2.5/onecall?"
|
||||||
self.key = key
|
self.key = key
|
||||||
@ -15,6 +18,8 @@ class WeatherFetch():
|
|||||||
|
|
||||||
|
|
||||||
data = {"lat" : location[0], "lon" : location[1], "exclude" : "minutely,hourly", "appid" : self.key, "units" : "metric"}
|
data = {"lat" : location[0], "lon" : location[1], "exclude" : "minutely,hourly", "appid" : self.key, "units" : "metric"}
|
||||||
|
self.calls += 1
|
||||||
|
logger.info("Just fetched weather. ({}th time)".format(self.calls))
|
||||||
# today = datetime.datetime.today().weekday()
|
# today = datetime.datetime.today().weekday()
|
||||||
# days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
# days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ class Alias(BotFunc):
|
|||||||
|
|
||||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||||
test = self.dispatcher
|
test = self.dispatcher
|
||||||
print(self.dispatcher.handlers[0])
|
|
||||||
keyboard = [
|
keyboard = [
|
||||||
[InlineKeyboardButton("All aliases", callback_data="all")],
|
[InlineKeyboardButton("All aliases", callback_data="all")],
|
||||||
[InlineKeyboardButton("Create new alias", callback_data="new")],
|
[InlineKeyboardButton("Create new alias", callback_data="new")],
|
||||||
|
@ -163,7 +163,6 @@ class Lists(BotFunc):
|
|||||||
item = update.message.text
|
item = update.message.text
|
||||||
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
||||||
sl = it.content
|
sl = it.content
|
||||||
print("SLSLLLL: {} -- {}".format(sl, type(sl)))
|
|
||||||
sl += item + "<-->"
|
sl += item + "<-->"
|
||||||
self.db.lists.update(content=sl).where(self.db.lists.name == self.current_name).execute()
|
self.db.lists.update(content=sl).where(self.db.lists.name == self.current_name).execute()
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class Status(BotFunc):
|
|||||||
query = update.callback_query
|
query = update.callback_query
|
||||||
wanted = query.data.replace("status-","")
|
wanted = query.data.replace("status-","")
|
||||||
query.answer()
|
query.answer()
|
||||||
with open("persistence/complete.log") as l:
|
with open("persistence/server.log") as l:
|
||||||
query.message.reply_document(l)
|
query.message.reply_document(l)
|
||||||
|
|
||||||
super().log_activity(read = False, execute = False, send = True)
|
super().log_activity(read = False, execute = False, send = True)
|
||||||
|
@ -12,16 +12,12 @@ class ClockBackend:
|
|||||||
self.weather_raw = {}
|
self.weather_raw = {}
|
||||||
self.weather_face_swap = False
|
self.weather_face_swap = False
|
||||||
|
|
||||||
self.brightness = 1
|
|
||||||
self.brightness_overwrite = {"value" : 1, "duration" : 0}
|
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.out = self.modules["broadcast"]
|
self.out = self.modules["broadcast"]
|
||||||
helpers.timer.RepeatedTimer(15, self.clock_loop)
|
helpers.timer.RepeatedTimer(15, self.clock_loop)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def clock_loop(self):
|
def clock_loop(self):
|
||||||
t = int(datetime.datetime.now().strftime("%H%M"))
|
t = int(datetime.datetime.now().strftime("%H%M"))
|
||||||
|
|
||||||
@ -40,7 +36,7 @@ class ClockBackend:
|
|||||||
self.weather["weather"] = "error"
|
self.weather["weather"] = "error"
|
||||||
self.weather["high"] = "error"
|
self.weather["high"] = "error"
|
||||||
self.weather["low"] = "error"
|
self.weather["low"] = "error"
|
||||||
# if weather == self.weather.raw do nothing
|
|
||||||
self.weather_face_swap = not self.weather_face_swap
|
self.weather_face_swap = not self.weather_face_swap
|
||||||
|
|
||||||
self.send_face()
|
self.send_face()
|
||||||
@ -54,23 +50,10 @@ class ClockBackend:
|
|||||||
if self.weather_face_swap:
|
if self.weather_face_swap:
|
||||||
matrices = [matrices[0], matrices[2], matrices[1]]
|
matrices = [matrices[0], matrices[2], matrices[1]]
|
||||||
|
|
||||||
# apply brightness
|
matrices = [m.tolist() for m in matrices]
|
||||||
b = self.get_brightness()
|
|
||||||
matrices = [(b * m).tolist() for m in matrices]
|
|
||||||
self.out.queue.append({"matrices" : matrices})
|
self.out.queue.append({"matrices" : matrices})
|
||||||
|
|
||||||
|
|
||||||
def get_brightness(self):
|
|
||||||
"""Checks, what brightness rules to apply"""
|
|
||||||
|
|
||||||
is_WE = datetime.datetime.now().weekday() > 4
|
|
||||||
now = int(datetime.datetime.now().strftime("%H%M"))
|
|
||||||
if (is_WE and (now > 1000 and now < 2200)) or ((not is_WE) and (now > 800 and now < 2130)):
|
|
||||||
brightness = 0.8
|
|
||||||
else:
|
|
||||||
brightness = 0.01
|
|
||||||
|
|
||||||
return brightness
|
|
||||||
|
|
||||||
|
|
||||||
# def text_scroll(self, text, color=[[200,200,200]]):
|
# def text_scroll(self, text, color=[[200,200,200]]):
|
||||||
|
@ -21,25 +21,25 @@ class ClockFace:
|
|||||||
self.kill_output = False
|
self.kill_output = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# helpers.timer.RepeatedTimer(60, self.clock_loop)
|
|
||||||
# # schedule for in 60 seconds
|
|
||||||
Thread(target = self.clock_loop).start()
|
Thread(target = self.clock_loop).start()
|
||||||
|
|
||||||
|
|
||||||
# TODO Turn off when button pressed?
|
|
||||||
|
|
||||||
def clock_loop(self):
|
def clock_loop(self):
|
||||||
|
while True: # TODO: allow this to be exited gracefully
|
||||||
|
|
||||||
t_start = datetime.datetime.now()
|
t_start = datetime.datetime.now()
|
||||||
|
|
||||||
t_minutes = int(datetime.datetime.now().strftime("%H%M"))
|
self.set_brightness()
|
||||||
|
|
||||||
has_queue, data = self.modules["receive"].fetch_data()
|
has_queue, data = self.modules["receive"].fetch_data()
|
||||||
self.set_brightness()
|
tnext = 1 if has_queue else 30
|
||||||
|
|
||||||
if data == {}:
|
if data == {}:
|
||||||
matrices = self.MOP.get_fallback()
|
matrices = self.MOP.get_fallback()
|
||||||
|
matrices[0][0,0] = [255, 0, 0] # red dot on the top left
|
||||||
else:
|
else:
|
||||||
matrices = [np.asarray(d).astype(int) for d in data["matrices"]]
|
matrices = [np.asarray(d).astype(int) for d in data["matrices"]]
|
||||||
|
matrices[0][0,0] = [0, 255, 0] # green dot on the top left
|
||||||
|
|
||||||
if not self.kill_output:
|
if not self.kill_output:
|
||||||
self.IO.put(matrices)
|
self.IO.put(matrices)
|
||||||
@ -47,18 +47,12 @@ class ClockFace:
|
|||||||
z = np.zeros((16,16,3))
|
z = np.zeros((16,16,3))
|
||||||
self.IO.put([z,z,z])
|
self.IO.put([z,z,z])
|
||||||
|
|
||||||
if has_queue:
|
|
||||||
tnext = 1
|
|
||||||
else:
|
|
||||||
tnext = 30
|
|
||||||
|
|
||||||
|
|
||||||
t_end = datetime.datetime.now()
|
t_end = datetime.datetime.now()
|
||||||
delta_planned = datetime.timedelta(seconds = tnext)
|
delta_planned = datetime.timedelta(seconds = tnext)
|
||||||
delta = delta_planned - (t_end - t_start)
|
delta = delta_planned - (t_end - t_start)
|
||||||
|
|
||||||
time.sleep(max(delta.total_seconds(), 0))
|
time.sleep(max(delta.total_seconds(), 0))
|
||||||
self.clock_loop()
|
|
||||||
|
|
||||||
|
|
||||||
def set_brightness(self):
|
def set_brightness(self):
|
||||||
@ -66,8 +60,6 @@ class ClockFace:
|
|||||||
|
|
||||||
is_WE = datetime.datetime.now().weekday() > 4
|
is_WE = datetime.datetime.now().weekday() > 4
|
||||||
now = int(datetime.datetime.now().strftime("%H%M"))
|
now = int(datetime.datetime.now().strftime("%H%M"))
|
||||||
if (is_WE and (now > 1000 and now < 2200)) or ((not is_WE) and (now > 830 and now < 2130)):
|
|
||||||
self.kill_output = False
|
self.kill_output = (now < 1000 or now > 2200) if is_WE else (now < 830 or now > 2130)
|
||||||
else:
|
|
||||||
self.kill_output = True
|
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ class ClockOut:
|
|||||||
self.screen.fill((0, 0, 0))
|
self.screen.fill((0, 0, 0))
|
||||||
for event in pygame.event.get(): # User did something
|
for event in pygame.event.get(): # User did something
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
print("Exiting...")
|
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
10
launcher.py
10
launcher.py
@ -3,6 +3,9 @@ import logging
|
|||||||
from persistence import p_io, p_out
|
from persistence import p_io, p_out
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Launcher:
|
class Launcher:
|
||||||
"""base launcher that launches other submodules"""
|
"""base launcher that launches other submodules"""
|
||||||
|
|
||||||
@ -11,8 +14,7 @@ class Launcher:
|
|||||||
self.persistence = p_io.PersistentDict("persistence/prst.json")
|
self.persistence = p_io.PersistentDict("persistence/prst.json")
|
||||||
self.db = p_out.DBLogging()
|
self.db = p_out.DBLogging()
|
||||||
|
|
||||||
self.logger = logging.getLogger(__name__)
|
logger.info(self.__class__.__name__ + " initialized")
|
||||||
self.logger.info(self.__class__.__name__ + " initialized")
|
|
||||||
|
|
||||||
self.modules = modules
|
self.modules = modules
|
||||||
if len(self.persistence) == 0:
|
if len(self.persistence) == 0:
|
||||||
@ -26,7 +28,7 @@ class Launcher:
|
|||||||
def launch_modules(self):
|
def launch_modules(self):
|
||||||
|
|
||||||
for module in self.modules.values():
|
for module in self.modules.values():
|
||||||
self.logger.info("Starting module "+ module.__class__.__name__)
|
logger.info("Starting module "+ module.__class__.__name__)
|
||||||
module.modules = self.modules
|
module.modules = self.modules
|
||||||
module.persistence = self.persistence
|
module.persistence = self.persistence
|
||||||
module.db = self.db
|
module.db = self.db
|
||||||
@ -34,7 +36,7 @@ class Launcher:
|
|||||||
|
|
||||||
|
|
||||||
def init_persistence(self):
|
def init_persistence(self):
|
||||||
self.logger.warning("No persistence found, created a new one")
|
logger.warning("No persistence found, created a new one")
|
||||||
|
|
||||||
self.persistence["global"] ={
|
self.persistence["global"] ={
|
||||||
"lists" : {},
|
"lists" : {},
|
||||||
|
@ -25,7 +25,7 @@ class DBModel(Model):
|
|||||||
# db.close()
|
# db.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Could not write to db. Dropping content of {}".format(self.__class__.__name__))
|
logger.error("Could not write to db. Dropping content of {}".format(self.__class__.__name__))
|
||||||
print(e)
|
logger.error(e)
|
||||||
# db.atomic().rollback()
|
# db.atomic().rollback()
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class Metric(DBModel):
|
|||||||
time = DateTimeField()
|
time = DateTimeField()
|
||||||
|
|
||||||
|
|
||||||
|
### Actual metrics:
|
||||||
|
|
||||||
class SensorMetric(Metric):
|
class SensorMetric(Metric):
|
||||||
# this is a continuous metric
|
# this is a continuous metric
|
||||||
|
@ -83,5 +83,5 @@ def create_struct(struct_type, own_name, parent_name, *args, **kwargs):
|
|||||||
def append(self, *args):
|
def append(self, *args):
|
||||||
super().append(*args)
|
super().append(*args)
|
||||||
self.parent.__setitem__(self.name, self)
|
self.parent.__setitem__(self.name, self)
|
||||||
print(*args)
|
|
||||||
return HookedStruct(own_name, parent_name, *args, **kwargs)
|
return HookedStruct(own_name, parent_name, *args, **kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user