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 datetime
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
class WeatherFetch():
|
||||
def __init__(self, key):
|
||||
self.last_fetch = datetime.datetime.fromtimestamp(0)
|
||||
self.last_weather = ""
|
||||
self.calls = 0
|
||||
|
||||
self.url = "https://api.openweathermap.org/data/2.5/onecall?"
|
||||
self.key = key
|
||||
@ -15,6 +18,8 @@ class WeatherFetch():
|
||||
|
||||
|
||||
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()
|
||||
# days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||
|
||||
|
@ -26,7 +26,6 @@ class Alias(BotFunc):
|
||||
|
||||
def entry_point(self, update: Update, context: CallbackContext) -> None:
|
||||
test = self.dispatcher
|
||||
print(self.dispatcher.handlers[0])
|
||||
keyboard = [
|
||||
[InlineKeyboardButton("All aliases", callback_data="all")],
|
||||
[InlineKeyboardButton("Create new alias", callback_data="new")],
|
||||
|
@ -163,7 +163,6 @@ class Lists(BotFunc):
|
||||
item = update.message.text
|
||||
it = self.db.lists.get(self.db.lists.name == self.current_name)
|
||||
sl = it.content
|
||||
print("SLSLLLL: {} -- {}".format(sl, type(sl)))
|
||||
sl += item + "<-->"
|
||||
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
|
||||
wanted = query.data.replace("status-","")
|
||||
query.answer()
|
||||
with open("persistence/complete.log") as l:
|
||||
with open("persistence/server.log") as l:
|
||||
query.message.reply_document(l)
|
||||
|
||||
super().log_activity(read = False, execute = False, send = True)
|
||||
|
@ -12,15 +12,11 @@ class ClockBackend:
|
||||
self.weather_raw = {}
|
||||
self.weather_face_swap = False
|
||||
|
||||
self.brightness = 1
|
||||
self.brightness_overwrite = {"value" : 1, "duration" : 0}
|
||||
|
||||
|
||||
def start(self):
|
||||
self.out = self.modules["broadcast"]
|
||||
helpers.timer.RepeatedTimer(15, self.clock_loop)
|
||||
|
||||
|
||||
|
||||
def clock_loop(self):
|
||||
t = int(datetime.datetime.now().strftime("%H%M"))
|
||||
@ -40,7 +36,7 @@ class ClockBackend:
|
||||
self.weather["weather"] = "error"
|
||||
self.weather["high"] = "error"
|
||||
self.weather["low"] = "error"
|
||||
# if weather == self.weather.raw do nothing
|
||||
|
||||
self.weather_face_swap = not self.weather_face_swap
|
||||
|
||||
self.send_face()
|
||||
@ -54,23 +50,10 @@ class ClockBackend:
|
||||
if self.weather_face_swap:
|
||||
matrices = [matrices[0], matrices[2], matrices[1]]
|
||||
|
||||
# apply brightness
|
||||
b = self.get_brightness()
|
||||
matrices = [(b * m).tolist() for m in matrices]
|
||||
matrices = [m.tolist() for m in 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]]):
|
||||
|
@ -21,44 +21,38 @@ class ClockFace:
|
||||
self.kill_output = False
|
||||
|
||||
def start(self):
|
||||
# helpers.timer.RepeatedTimer(60, self.clock_loop)
|
||||
# # schedule for in 60 seconds
|
||||
Thread(target = self.clock_loop).start()
|
||||
|
||||
|
||||
# TODO Turn off when button pressed?
|
||||
|
||||
def clock_loop(self):
|
||||
t_start = datetime.datetime.now()
|
||||
|
||||
t_minutes = int(datetime.datetime.now().strftime("%H%M"))
|
||||
while True: # TODO: allow this to be exited gracefully
|
||||
|
||||
has_queue, data = self.modules["receive"].fetch_data()
|
||||
self.set_brightness()
|
||||
|
||||
if data == {}:
|
||||
matrices = self.MOP.get_fallback()
|
||||
else:
|
||||
matrices = [np.asarray(d).astype(int) for d in data["matrices"]]
|
||||
|
||||
if not self.kill_output:
|
||||
self.IO.put(matrices)
|
||||
else:
|
||||
z = np.zeros((16,16,3))
|
||||
self.IO.put([z,z,z])
|
||||
|
||||
if has_queue:
|
||||
tnext = 1
|
||||
else:
|
||||
tnext = 30
|
||||
t_start = datetime.datetime.now()
|
||||
|
||||
self.set_brightness()
|
||||
|
||||
t_end = datetime.datetime.now()
|
||||
delta_planned = datetime.timedelta(seconds = tnext)
|
||||
delta = delta_planned - (t_end - t_start)
|
||||
|
||||
time.sleep(max(delta.total_seconds(), 0))
|
||||
self.clock_loop()
|
||||
has_queue, data = self.modules["receive"].fetch_data()
|
||||
tnext = 1 if has_queue else 30
|
||||
|
||||
if data == {}:
|
||||
matrices = self.MOP.get_fallback()
|
||||
matrices[0][0,0] = [255, 0, 0] # red dot on the top left
|
||||
else:
|
||||
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:
|
||||
self.IO.put(matrices)
|
||||
else:
|
||||
z = np.zeros((16,16,3))
|
||||
self.IO.put([z,z,z])
|
||||
|
||||
|
||||
t_end = datetime.datetime.now()
|
||||
delta_planned = datetime.timedelta(seconds = tnext)
|
||||
delta = delta_planned - (t_end - t_start)
|
||||
|
||||
time.sleep(max(delta.total_seconds(), 0))
|
||||
|
||||
|
||||
def set_brightness(self):
|
||||
@ -66,8 +60,6 @@ class ClockFace:
|
||||
|
||||
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 > 830 and now < 2130)):
|
||||
self.kill_output = False
|
||||
else:
|
||||
self.kill_output = True
|
||||
|
||||
self.kill_output = (now < 1000 or now > 2200) if is_WE else (now < 830 or now > 2130)
|
||||
|
||||
|
@ -26,7 +26,6 @@ class ClockOut:
|
||||
self.screen.fill((0, 0, 0))
|
||||
for event in pygame.event.get(): # User did something
|
||||
if event.type == pygame.QUIT:
|
||||
print("Exiting...")
|
||||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
|
10
launcher.py
10
launcher.py
@ -3,6 +3,9 @@ import logging
|
||||
from persistence import p_io, p_out
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Launcher:
|
||||
"""base launcher that launches other submodules"""
|
||||
|
||||
@ -11,8 +14,7 @@ class Launcher:
|
||||
self.persistence = p_io.PersistentDict("persistence/prst.json")
|
||||
self.db = p_out.DBLogging()
|
||||
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.logger.info(self.__class__.__name__ + " initialized")
|
||||
logger.info(self.__class__.__name__ + " initialized")
|
||||
|
||||
self.modules = modules
|
||||
if len(self.persistence) == 0:
|
||||
@ -26,7 +28,7 @@ class Launcher:
|
||||
def launch_modules(self):
|
||||
|
||||
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.persistence = self.persistence
|
||||
module.db = self.db
|
||||
@ -34,7 +36,7 @@ class Launcher:
|
||||
|
||||
|
||||
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"] ={
|
||||
"lists" : {},
|
||||
|
@ -25,7 +25,7 @@ class DBModel(Model):
|
||||
# db.close()
|
||||
except Exception as e:
|
||||
logger.error("Could not write to db. Dropping content of {}".format(self.__class__.__name__))
|
||||
print(e)
|
||||
logger.error(e)
|
||||
# db.atomic().rollback()
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ class Metric(DBModel):
|
||||
time = DateTimeField()
|
||||
|
||||
|
||||
|
||||
### Actual metrics:
|
||||
|
||||
class SensorMetric(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):
|
||||
super().append(*args)
|
||||
self.parent.__setitem__(self.name, self)
|
||||
print(*args)
|
||||
|
||||
return HookedStruct(own_name, parent_name, *args, **kwargs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user