From 6ef7569705f6b24bdbb9d0db7175ade0f15e650a Mon Sep 17 00:00:00 2001 From: Lars Bogner Date: Wed, 20 Jan 2021 12:30:44 +0100 Subject: [PATCH] most of it implemented --- .vscode/settings.json | 10 +++- RaspberryPie/dataHandling.py | 43 +++++++++++++++++ RaspberryPie/database.db | Bin 0 -> 32768 bytes RaspberryPie/hardwareControl.py | 80 ++++++++++++++++++------------- RaspberryPie/internetHandling.py | 1 - RaspberryPie/logger.py | 4 +- RaspberryPie/raspberryPie.py | 30 ++++++++++-- RaspberryPie/tasks.py | 2 + 8 files changed, 131 insertions(+), 39 deletions(-) create mode 100644 RaspberryPie/dataHandling.py create mode 100644 RaspberryPie/database.db diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ec39be..4529f72 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,11 @@ { - "cSpell.enabled": false + "cSpell.enabled": false, + "sqltools.connections": [ + { + "previewLimit": 50, + "driver": "SQLite", + "name": "database", + "database": "${workspaceFolder:RaspberryPie}/RaspberryPie/database.db" + } + ] } \ No newline at end of file diff --git a/RaspberryPie/dataHandling.py b/RaspberryPie/dataHandling.py new file mode 100644 index 0000000..c53566b --- /dev/null +++ b/RaspberryPie/dataHandling.py @@ -0,0 +1,43 @@ +#general imports +import datetime +import sqlite3 + +# imports from Project +from RaspberryPie.logger import captScribe +from RaspberryPie.config import config + + +class BGenSecretary: + def __init__(self, database_path, image_path): + self.database = database_path + self.image_path = image_path + + def _record(self, data: dict): + connection = None + try: + connection = sqlite3.connect(self.database) + cursor = connection.cursor() + for typ in data: + time = datetime.datetime.now() + data[typ]["time_string"] = str(time) + data[typ]["unix_time"] = int(time.timestamp()) + command = "INSERT INTO {} ({}) VALUES ({})".format(typ, str([i for i in data[typ]])[1:-1], str([data[typ][i] for i in data[typ]])[1:-1]) + cursor.execute(command) + captScribe.info("Inserted data into table '{}' of database".format(typ), "BGenSecretary._record") + connection.commit() + except sqlite3.Error as e: + captScribe.error(str(e), "BGenSecretary._record") + finally: + if connection is sqlite3.Connection: + connection.close() + + def recordPicture(self, picture): + with open("{}/{}.jpg".format(self.image_path, str(datetime.datetime.now())), "w") as f: + f.write(picture) + + self._record({"picture": {"picture": picture}}) + + def recordAir(self, data): + self._record({"air": {"temperature": data[0], "humidity": data[1]}}) + +bGenSecretary = BGenSecretary(config["File Locations"]["database_file"], config["File Locations"],["image_path"]) \ No newline at end of file diff --git a/RaspberryPie/database.db b/RaspberryPie/database.db new file mode 100644 index 0000000000000000000000000000000000000000..bd5446f40be1569e08df31ac6de2e46cc894835e GIT binary patch literal 32768 zcmeI*!Ee$~9Ki8cU@*v_7?Ppk@9M%5;R4JgSxZvTMC z`6uYb|HPvQ55~i;{sA65_zEQpFqd7-lzkf>?fbpHm*4xmUYfM&i|w-OIr7zhw`F_s zp-2l&6HlcSLc~;=4@yYw@2V0}WwdFdgA4XC@nGXaGPNk?7EZL(x1_0mT{ua7O4%v< zf?hNsfB*srAb<|L?cI6t|0kyI4L(n2d-UjLESt+|$4@+aXV0mW)~#CA z2zGPpRikJb(kebH8!{h6^KvN>&%4chykuI&hEbK~mL<(vxhyNy(q^$*m(Pv5EY_^8 zlBq`6G)zm@%+hwvSXCYSZTGO@xh-e9zu!D;v5c2$$Y5AMeBkbS{jTccw8i-zPqoqWx^DaRFt4$UJ*RcxbnRi*%CYQE<4wQiHeK&+KJG^n z%X&e)pI(%!kKDf%%@%W-aNAAiu-DmBx2_Gl@9hujjo?CPtOWob-oE3!#6% z#F(6d00IagfB*srAb0tg_000Iag zfB*srAb`NE2t<