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
|
import base64
|
||||||
|
|
||||||
# imports from Project
|
# imports from Project
|
||||||
from RaspberryPie.logger import captScribe
|
import RaspberryPie.config as config
|
||||||
from RaspberryPie.config import config
|
|
||||||
|
|
||||||
|
captScribe = None
|
||||||
|
|
||||||
|
def _set_captScribe(_captScribe):
|
||||||
|
global captScribe
|
||||||
|
captScribe = _captScribe
|
||||||
|
|
||||||
class BGenSecretary:
|
class BGenSecretary:
|
||||||
def __init__(self, database_path, image_path):
|
def __init__(self, database_path, image_path):
|
||||||
@@ -27,6 +31,9 @@ class BGenSecretary:
|
|||||||
cursor.execute(command)
|
cursor.execute(command)
|
||||||
captScribe.info("Inserted data into table '{}' of database".format(typ), "BGenSecretary._record")
|
captScribe.info("Inserted data into table '{}' of database".format(typ), "BGenSecretary._record")
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
|
||||||
|
with open(config.config["FileLocations"]["lastChangeFile"], 'w') as f:
|
||||||
|
f.write(str(int(datetime.datetime.now().timestamp())))
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
captScribe.error(str(e), "BGenSecretary._record")
|
captScribe.error(str(e), "BGenSecretary._record")
|
||||||
finally:
|
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]}
|
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
|
import datetime
|
||||||
from RaspberryPie.config import config
|
import RaspberryPie.config as config
|
||||||
from RaspberryPie.dataHandling import bGenSecretary
|
import RaspberryPie.dataHandling as dataHandling
|
||||||
|
|
||||||
def time(): return ""
|
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
|
from flask import Flask, render_template, make_response
|
||||||
import json
|
import json
|
||||||
|
import signal
|
||||||
|
|
||||||
import RaspberryPie.flaskAddons as fa
|
import RaspberryPie.flaskAddons as fa
|
||||||
|
|
||||||
@@ -54,3 +55,7 @@ def ininitisteGPIO(state):
|
|||||||
@app.route("/initiate/shutdown/")
|
@app.route("/initiate/shutdown/")
|
||||||
def initiateShutdown():
|
def initiateShutdown():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@app.route("/lastChange/")
|
||||||
|
def lastChange():
|
||||||
|
return str(fa.lastChange())
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#general imports
|
#general imports
|
||||||
|
from RaspberryPie.logger import CaptScribe
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@@ -8,9 +9,15 @@ from picamera import PiCamera
|
|||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
# imports from project
|
# imports from project
|
||||||
from RaspberryPie.config import config
|
import RaspberryPie.config as config
|
||||||
from RaspberryPie.logger import captScribe
|
import RaspberryPie.dataHandling as dataHandling
|
||||||
from RaspberryPie.dataHandling import bGenSecretary
|
|
||||||
|
captScribe = None
|
||||||
|
|
||||||
|
def _set_captScribe(_captScribe):
|
||||||
|
global captScribe
|
||||||
|
captScribe = _captScribe
|
||||||
|
dataHandling._set_captScribe(_captScribe)
|
||||||
|
|
||||||
|
|
||||||
class MajGenGPIOController:
|
class MajGenGPIOController:
|
||||||
@@ -69,12 +76,12 @@ class MajGenObserver:
|
|||||||
class MajGenAirChecker(MajGenObserver):
|
class MajGenAirChecker(MajGenObserver):
|
||||||
def __init__(self, schedule_timing=None):
|
def __init__(self, schedule_timing=None):
|
||||||
if not schedule_timing:
|
if not schedule_timing:
|
||||||
schedule_timing = config["Timing"]["environmentdelta"]
|
schedule_timing = config.config["Timing"]["environmentdelta"]
|
||||||
super().__init__(schedule_timing)
|
super().__init__(schedule_timing)
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
sensor = Adafruit_DHT.DHT22
|
sensor = Adafruit_DHT.DHT22
|
||||||
pin = int(config["Hardware"]["dhtpin"])
|
pin = int(config.config["Hardware"]["dhtpin"])
|
||||||
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
|
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
|
||||||
if humidity is None or temperature is None:
|
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")
|
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):
|
class MajGenVisualObserver(MajGenObserver):
|
||||||
def __init__(self, schedule_timing=None):
|
def __init__(self, schedule_timing=None):
|
||||||
if not schedule_timing:
|
if not schedule_timing:
|
||||||
schedule_timing = config["Timing"]["picturedelta"]
|
schedule_timing = config.config["Timing"]["picturedelta"]
|
||||||
super().__init__(schedule_timing)
|
super().__init__(schedule_timing)
|
||||||
|
|
||||||
def execute():
|
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()
|
majGenVisualObserver = MajGenVisualObserver()
|
||||||
majGenAirChecker = MajGenAirChecker()
|
majGenAirChecker = MajGenAirChecker()
|
||||||
majGenAirRecoder = MajGenAirRecoder(bGenSecretary)
|
majGenAirRecoder = MajGenAirRecoder(dataHandling.bGenSecretary)
|
||||||
majGenVisualRecoder = MajGenVisualRecoder(bGenSecretary)
|
majGenVisualRecoder = MajGenVisualRecoder(dataHandling.bGenSecretary)
|
||||||
|
|||||||
@@ -7,8 +7,13 @@ import email
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
from RaspberryPie.logger import captScribe
|
import RaspberryPie.config as config
|
||||||
from RaspberryPie.config import config
|
|
||||||
|
captScribe = None
|
||||||
|
|
||||||
|
def _set_captScribe(_captScribe):
|
||||||
|
global captScribe
|
||||||
|
captScribe = _captScribe
|
||||||
|
|
||||||
class MajGenApiCom:
|
class MajGenApiCom:
|
||||||
class Telegram:
|
class Telegram:
|
||||||
@@ -26,7 +31,7 @@ class MajGenApiCom:
|
|||||||
def __init__(self, email, dropbox):
|
def __init__(self, email, dropbox):
|
||||||
self.email = email
|
self.email = email
|
||||||
self.dropbox = dropbox
|
self.dropbox = dropbox
|
||||||
self.mail_config = config["Mail"]
|
self.mail_config = config.config["Mail"]
|
||||||
|
|
||||||
def upload_dropbox(self, filename, content):
|
def upload_dropbox(self, filename, content):
|
||||||
try:
|
try:
|
||||||
@@ -118,4 +123,4 @@ class MajGenApiCom:
|
|||||||
captScribe.error("Logout of imap failed.", "MajGenApiCom.delete_mail")
|
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
|
# general imports
|
||||||
import logging
|
import logging
|
||||||
from RaspberryPie.config import config
|
|
||||||
|
|
||||||
|
|
||||||
class CaptScribe:
|
class CaptScribe:
|
||||||
@@ -38,6 +37,3 @@ class CaptScribe:
|
|||||||
def debug(self, msg, func=""):
|
def debug(self, msg, func=""):
|
||||||
for logger in self.loggers:
|
for logger in self.loggers:
|
||||||
logger.debug(func.upper() + ": " + msg)
|
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
|
Capt << BGen << MajGen << LtGen << Gen
|
||||||
"""
|
"""
|
||||||
# imports from project
|
# imports from project
|
||||||
from RaspberryPie.tasks import Task
|
import RaspberryPie.tasks as tasks
|
||||||
from RaspberryPie.hardwareControl import majGenGPIOController, majGenVisualRecorder, majGenAirRecoder
|
import RaspberryPie.hardwareControl as hardwareControl
|
||||||
from RaspberryPie.config import config
|
import RaspberryPie.config as config
|
||||||
from RaspberryPie.logger import captScribe
|
import RaspberryPie.logger as logger
|
||||||
from RaspberryPie.internetHandling import majGenApiCom, MajGenApiCom
|
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
|
ltGenInterpreter, genScheduler = None
|
||||||
|
|
||||||
tasks = [
|
tasks = [
|
||||||
Task(majGenGPIOController.open, lambda msg: 1 if ("auf" == msg.subject.lower() or "open" == 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),
|
||||||
Task(majGenGPIOController.close, lambda msg: 1 if ("zu" == msg.subject.lower() or "close" == 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:
|
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:
|
if not schedule_timing:
|
||||||
schedule_timing = config["Timing"]["maildelta"]
|
schedule_timing = config.config.config["Timing"]["maildelta"]
|
||||||
self.schedule_timing
|
self.schedule_timing
|
||||||
self.tasks = tasks
|
self.tasks = tasks
|
||||||
self.communicator = communicator
|
self.communicator = communicator
|
||||||
@@ -67,15 +71,15 @@ class GenScheduler:
|
|||||||
captScribe.critical("A not expected error occured: {}".format(str(e)), "GenScheduler.execute")
|
captScribe.critical("A not expected error occured: {}".format(str(e)), "GenScheduler.execute")
|
||||||
|
|
||||||
def initiate_shutdown(self, reboot=True):
|
def initiate_shutdown(self, reboot=True):
|
||||||
majGenGPIOController.finalMission()
|
hardwareControl.majGenGPIOController.finalMission()
|
||||||
reboot_str = lambda: " -r" if reboot else ""
|
reboot_str = lambda: " -r" if reboot else ""
|
||||||
os.system("shutdown{} 0".format(reboot_str()))
|
os.system("shutdown{} 0".format(reboot_str()))
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global ltGenInterpreter, genScheduler
|
global ltGenInterpreter, genScheduler
|
||||||
ltGenInterpreter = LtGenInterpreter(tasks, majGenApiCom)
|
ltGenInterpreter = LtGenInterpreter(tasks, internetHandling.majGenApiCom)
|
||||||
genScheduler = GenScheduler((ltGenInterpreter, majGenVisualRecorder, majGenAirRecoder))
|
genScheduler = GenScheduler((ltGenInterpreter, hardwareControl.majGenVisualRecorder, hardwareControl.majGenAirRecoder))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from RaspberryPie.internetHandling import MajGenApiCom
|
from RaspberryPie.internetHandling import MajGenApiCom
|
||||||
|
|
||||||
class Task:
|
class tasks.Task:
|
||||||
def __init__(self, function, check):
|
def __init__(self, function, check):
|
||||||
self.function = function
|
self.function = function
|
||||||
self.check = check
|
self.check = check
|
||||||
|
|||||||
Reference in New Issue
Block a user