I Don't know if it's working...
I just have no f**** clue.... There's no structure in this god damn project but let's hope for the best.
This commit is contained in:
@@ -4,9 +4,13 @@ import sqlite3
|
||||
import base64
|
||||
|
||||
# imports from Project
|
||||
from RaspberryPie.logger import captScribe
|
||||
from RaspberryPie.config import config
|
||||
import RaspberryPie.config as config
|
||||
|
||||
captScribe = None
|
||||
|
||||
def _set_captScribe(_captScribe):
|
||||
global captScribe
|
||||
captScribe = _captScribe
|
||||
|
||||
class BGenSecretary:
|
||||
def __init__(self, database_path, image_path):
|
||||
@@ -27,6 +31,9 @@ class BGenSecretary:
|
||||
cursor.execute(command)
|
||||
captScribe.info("Inserted data into table '{}' of database".format(typ), "BGenSecretary._record")
|
||||
connection.commit()
|
||||
|
||||
with open(config.config["FileLocations"]["lastChangeFile"], 'w') as f:
|
||||
f.write(str(int(datetime.datetime.now().timestamp())))
|
||||
except sqlite3.Error as e:
|
||||
captScribe.error(str(e), "BGenSecretary._record")
|
||||
finally:
|
||||
@@ -94,4 +101,4 @@ class BGenSecretary:
|
||||
return {"unix_time": [entry[0] for entry in entries], "time_string": [entry[1] for entry in entries], "picture": [entry[2] for entry in entries]}
|
||||
|
||||
|
||||
bGenSecretary = BGenSecretary(config["File Locations"]["database_file"], config["File Locations"],["image_path"])
|
||||
bGenSecretary = BGenSecretary(config.config["File Locations"]["database_file"], config.config["File Locations"],["image_path"])
|
||||
@@ -1,19 +1,23 @@
|
||||
import datetime
|
||||
from RaspberryPie.config import config
|
||||
from RaspberryPie.dataHandling import bGenSecretary
|
||||
import RaspberryPie.config as config
|
||||
import RaspberryPie.dataHandling as dataHandling
|
||||
|
||||
def time(): return ""
|
||||
|
||||
def weatherUrls(): return [config["WeatherUrls"][i] for i in config["WeatherUrls"]]
|
||||
def weatherUrls(): return [config.config["WeatherUrls"][i] for i in config.config["WeatherUrls"]]
|
||||
|
||||
def getLatestAirData(): return bGenSecretary.fetchAir()
|
||||
def getLatestAirData(): return dataHandling.bGenSecretary.fetchAir()
|
||||
|
||||
def getLatestPicture(): return bGenSecretary.fetchAir()
|
||||
def getLatestPicture(): return dataHandling.bGenSecretary.fetchAir()
|
||||
|
||||
def getDataRangeAir(start: int, end: int): return bGenSecretary.fetchAir(datetime.datetime.utcfromtimestamp(end), datetime.datetime.utcfromtimestamp(start))
|
||||
def getDataRangeAir(start: int, end: int): return dataHandling.bGenSecretary.fetchAir(datetime.datetime.utcfromtimestamp(end), datetime.datetime.utcfromtimestamp(start))
|
||||
|
||||
def getDataRangePictures(start: int, end: int): return bGenSecretary.fetchPicture(datetime.datetime.utcfromtimestamp(end), datetime.datetime.utcfromtimestamp(start))
|
||||
def getDataRangePictures(start: int, end: int): return dataHandling.bGenSecretary.fetchPicture(datetime.datetime.utcfromtimestamp(end), datetime.datetime.utcfromtimestamp(start))
|
||||
|
||||
def getSingleAirData(time: int): return bGenSecretary.fetchAir(datetime.datetime.utcfromtimestamp(time))
|
||||
def getSingleAirData(time: int): return dataHandling.bGenSecretary.fetchAir(datetime.datetime.utcfromtimestamp(time))
|
||||
|
||||
def getSinglePicture(time: int): return bGenSecretary.fetchPicture(datetime.datetime.utcfromtimestamp(time))
|
||||
def getSinglePicture(time: int): return dataHandling.bGenSecretary.fetchPicture(datetime.datetime.utcfromtimestamp(time))
|
||||
|
||||
def lastChange():
|
||||
with open(config.config["FileLocations"]["lastChangeFile"], 'r') as f:
|
||||
return int(f.read())
|
||||
@@ -1,5 +1,6 @@
|
||||
from flask import Flask, render_template, make_response
|
||||
import json
|
||||
import signal
|
||||
|
||||
import RaspberryPie.flaskAddons as fa
|
||||
|
||||
@@ -54,3 +55,7 @@ def ininitisteGPIO(state):
|
||||
@app.route("/initiate/shutdown/")
|
||||
def initiateShutdown():
|
||||
pass
|
||||
|
||||
@app.route("/lastChange/")
|
||||
def lastChange():
|
||||
return str(fa.lastChange())
|
||||
@@ -1,4 +1,5 @@
|
||||
#general imports
|
||||
from RaspberryPie.logger import CaptScribe
|
||||
import time
|
||||
import datetime
|
||||
|
||||
@@ -8,9 +9,15 @@ from picamera import PiCamera
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
# imports from project
|
||||
from RaspberryPie.config import config
|
||||
from RaspberryPie.logger import captScribe
|
||||
from RaspberryPie.dataHandling import bGenSecretary
|
||||
import RaspberryPie.config as config
|
||||
import RaspberryPie.dataHandling as dataHandling
|
||||
|
||||
captScribe = None
|
||||
|
||||
def _set_captScribe(_captScribe):
|
||||
global captScribe
|
||||
captScribe = _captScribe
|
||||
dataHandling._set_captScribe(_captScribe)
|
||||
|
||||
|
||||
class MajGenGPIOController:
|
||||
@@ -69,12 +76,12 @@ class MajGenObserver:
|
||||
class MajGenAirChecker(MajGenObserver):
|
||||
def __init__(self, schedule_timing=None):
|
||||
if not schedule_timing:
|
||||
schedule_timing = config["Timing"]["environmentdelta"]
|
||||
schedule_timing = config.config["Timing"]["environmentdelta"]
|
||||
super().__init__(schedule_timing)
|
||||
|
||||
def execute():
|
||||
sensor = Adafruit_DHT.DHT22
|
||||
pin = int(config["Hardware"]["dhtpin"])
|
||||
pin = int(config.config["Hardware"]["dhtpin"])
|
||||
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
|
||||
if humidity is None or temperature is None:
|
||||
captScribe.warning("Error while reading DHT22 sensor. The received values are: Humidity: {}, Temperature: {}".format(str(humidity), str(temperature)), "MajGenObserver.get_sensorData")
|
||||
@@ -84,7 +91,7 @@ class MajGenAirChecker(MajGenObserver):
|
||||
class MajGenVisualObserver(MajGenObserver):
|
||||
def __init__(self, schedule_timing=None):
|
||||
if not schedule_timing:
|
||||
schedule_timing = config["Timing"]["picturedelta"]
|
||||
schedule_timing = config.config["Timing"]["picturedelta"]
|
||||
super().__init__(schedule_timing)
|
||||
|
||||
def execute():
|
||||
@@ -116,8 +123,8 @@ class MajGenVisualRecoder(MajGenVisualObserver):
|
||||
|
||||
|
||||
|
||||
majGenGPIOController = MajGenGPIOController(config["Hardware"]["pinopen"], config["Hardware"]["pinclose"], config["Timing"]["gpioswitchoff"])
|
||||
majGenGPIOController = MajGenGPIOController(config.config["Hardware"]["pinopen"], config.config["Hardware"]["pinclose"], config.config["Timing"]["gpioswitchoff"])
|
||||
majGenVisualObserver = MajGenVisualObserver()
|
||||
majGenAirChecker = MajGenAirChecker()
|
||||
majGenAirRecoder = MajGenAirRecoder(bGenSecretary)
|
||||
majGenVisualRecoder = MajGenVisualRecoder(bGenSecretary)
|
||||
majGenAirRecoder = MajGenAirRecoder(dataHandling.bGenSecretary)
|
||||
majGenVisualRecoder = MajGenVisualRecoder(dataHandling.bGenSecretary)
|
||||
|
||||
@@ -7,8 +7,13 @@ import email
|
||||
import datetime
|
||||
|
||||
|
||||
from RaspberryPie.logger import captScribe
|
||||
from RaspberryPie.config import config
|
||||
import RaspberryPie.config as config
|
||||
|
||||
captScribe = None
|
||||
|
||||
def _set_captScribe(_captScribe):
|
||||
global captScribe
|
||||
captScribe = _captScribe
|
||||
|
||||
class MajGenApiCom:
|
||||
class Telegram:
|
||||
@@ -26,7 +31,7 @@ class MajGenApiCom:
|
||||
def __init__(self, email, dropbox):
|
||||
self.email = email
|
||||
self.dropbox = dropbox
|
||||
self.mail_config = config["Mail"]
|
||||
self.mail_config = config.config["Mail"]
|
||||
|
||||
def upload_dropbox(self, filename, content):
|
||||
try:
|
||||
@@ -118,4 +123,4 @@ class MajGenApiCom:
|
||||
captScribe.error("Logout of imap failed.", "MajGenApiCom.delete_mail")
|
||||
|
||||
|
||||
majGenApiCom = MajGenApiCom({"address": config["Secrets"]["emailaddress"], "password": config["Secrets"]["emailpassword"]}, config["Secrets"]["dropboxtoken"])
|
||||
majGenApiCom = MajGenApiCom({"address": config.config["Secrets"]["emailaddress"], "password": config.config["Secrets"]["emailpassword"]}, config.config["Secrets"]["dropboxtoken"])
|
||||
@@ -1,6 +1,5 @@
|
||||
# general imports
|
||||
import logging
|
||||
from RaspberryPie.config import config
|
||||
|
||||
|
||||
class CaptScribe:
|
||||
@@ -38,6 +37,3 @@ class CaptScribe:
|
||||
def debug(self, msg, func=""):
|
||||
for logger in self.loggers:
|
||||
logger.debug(func.upper() + ": " + msg)
|
||||
|
||||
|
||||
captScribe = CaptScribe(config["File Locations"]["logfile_info"], config["File Locations"]["logfile_error"])
|
||||
@@ -9,25 +9,29 @@ All classes are ranked in their hierarchy, like this (ranks of the US Marines):
|
||||
Capt << BGen << MajGen << LtGen << Gen
|
||||
"""
|
||||
# imports from project
|
||||
from RaspberryPie.tasks import Task
|
||||
from RaspberryPie.hardwareControl import majGenGPIOController, majGenVisualRecorder, majGenAirRecoder
|
||||
from RaspberryPie.config import config
|
||||
from RaspberryPie.logger import captScribe
|
||||
from RaspberryPie.internetHandling import majGenApiCom, MajGenApiCom
|
||||
import RaspberryPie.tasks as tasks
|
||||
import RaspberryPie.hardwareControl as hardwareControl
|
||||
import RaspberryPie.config as config
|
||||
import RaspberryPie.logger as logger
|
||||
import RaspberryPie.internetHandling as internetHandling
|
||||
|
||||
captScribe = logger.CaptScribe(config.config.config["File Locations"]["logfile_info"], config.config.config["File Locations"]["logfile_error"])
|
||||
internetHandling._set_captScribe(captScribe)
|
||||
hardwareControl._set_captScribe(captScribe)
|
||||
|
||||
|
||||
ltGenInterpreter, genScheduler = None
|
||||
|
||||
tasks = [
|
||||
Task(majGenGPIOController.open, lambda msg: 1 if ("auf" == msg.subject.lower() or "open" == msg.subject.lower()) else 0),
|
||||
Task(majGenGPIOController.close, lambda msg: 1 if ("zu" == msg.subject.lower() or "close" == msg.subject.lower()) else 0)
|
||||
tasks.Task(hardwareControl.majGenGPIOController.open, lambda msg: 1 if ("auf" == msg.subject.lower() or "open" == msg.subject.lower()) else 0),
|
||||
tasks.Task(hardwareControl.majGenGPIOController.close, lambda msg: 1 if ("zu" == msg.subject.lower() or "close" == msg.subject.lower()) else 0)
|
||||
]
|
||||
|
||||
|
||||
class LtGenInterpreter:
|
||||
def __init__(self, tasks: list, communicator: MajGenApiCom, schedule_timing=None):
|
||||
def __init__(self, tasks: list, communicator: internetHandling.MajGenApiCom, schedule_timing=None):
|
||||
if not schedule_timing:
|
||||
schedule_timing = config["Timing"]["maildelta"]
|
||||
schedule_timing = config.config.config["Timing"]["maildelta"]
|
||||
self.schedule_timing
|
||||
self.tasks = tasks
|
||||
self.communicator = communicator
|
||||
@@ -67,15 +71,15 @@ class GenScheduler:
|
||||
captScribe.critical("A not expected error occured: {}".format(str(e)), "GenScheduler.execute")
|
||||
|
||||
def initiate_shutdown(self, reboot=True):
|
||||
majGenGPIOController.finalMission()
|
||||
hardwareControl.majGenGPIOController.finalMission()
|
||||
reboot_str = lambda: " -r" if reboot else ""
|
||||
os.system("shutdown{} 0".format(reboot_str()))
|
||||
|
||||
|
||||
def init():
|
||||
global ltGenInterpreter, genScheduler
|
||||
ltGenInterpreter = LtGenInterpreter(tasks, majGenApiCom)
|
||||
genScheduler = GenScheduler((ltGenInterpreter, majGenVisualRecorder, majGenAirRecoder))
|
||||
ltGenInterpreter = LtGenInterpreter(tasks, internetHandling.majGenApiCom)
|
||||
genScheduler = GenScheduler((ltGenInterpreter, hardwareControl.majGenVisualRecorder, hardwareControl.majGenAirRecoder))
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from RaspberryPie.internetHandling import MajGenApiCom
|
||||
|
||||
class Task:
|
||||
class tasks.Task:
|
||||
def __init__(self, function, check):
|
||||
self.function = function
|
||||
self.check = check
|
||||
|
||||
Reference in New Issue
Block a user