Fixes for Shared db
This commit is contained in:
@@ -6,4 +6,3 @@
|
||||
**/*.log
|
||||
thesillyhome_src/frontend/node_modules
|
||||
thesillyhome_src/frontend/static/data/*
|
||||
thesillyhome_src/startup/crontab
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
# echo "Starting to parse DB data"
|
||||
# python3 -m thesillyhome.model_creator.main
|
||||
# !/bin/bash
|
||||
echo "Starting to parse DB data"
|
||||
python3 -m thesillyhome.model_creator.main
|
||||
|
||||
|
||||
# echo "Starting Appdaemon"
|
||||
# eval "echo \"$(</thesillyhome_src/appdaemon/appdaemon.yaml)\"" > /thesillyhome_src/appdaemon/appdaemon.yaml
|
||||
# nohup appdaemon -c /thesillyhome_src/appdaemon/ &
|
||||
echo "Starting Appdaemon"
|
||||
eval "echo \"$(</thesillyhome_src/appdaemon/appdaemon.yaml)\"" > /thesillyhome_src/appdaemon/appdaemon.yaml
|
||||
nohup appdaemon -c /thesillyhome_src/appdaemon/ &
|
||||
|
||||
echo "Starting frontend on 0.0.0.0:2300"
|
||||
PORT=2300 node /thesillyhome_src/frontend/build/index.js
|
||||
|
||||
15
thesillyhome_src/thesillyhome/poetry.lock
generated
15
thesillyhome_src/thesillyhome/poetry.lock
generated
@@ -211,6 +211,18 @@ category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[[package]]
|
||||
name = "pymysql"
|
||||
version = "1.0.2"
|
||||
description = "Pure Python MySQL Driver"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[package.extras]
|
||||
rsa = ["cryptography"]
|
||||
ed25519 = ["PyNaCl (>=1.4.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "pyparsing"
|
||||
version = "3.0.9"
|
||||
@@ -373,7 +385,7 @@ python-versions = ">=3.7"
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = ">=3.9,<3.11"
|
||||
content-hash = "25bbafe3e67d9cec86771f552b6a8e3b778a623bab19883c876de92e7db081df"
|
||||
content-hash = "715436b9be56e29a122b69a236af88e44471c1797b4606b7bd12c90f29b70374"
|
||||
|
||||
[metadata.files]
|
||||
black = []
|
||||
@@ -587,6 +599,7 @@ psycopg2 = [
|
||||
{file = "psycopg2-2.9.3-cp39-cp39-win_amd64.whl", hash = "sha256:06f32425949bd5fe8f625c49f17ebb9784e1e4fe928b7cce72edc36fb68e4c0c"},
|
||||
{file = "psycopg2-2.9.3.tar.gz", hash = "sha256:8e841d1bf3434da985cc5ef13e6f75c8981ced601fd70cc6bf33351b91562981"},
|
||||
]
|
||||
pymysql = []
|
||||
pyparsing = [
|
||||
{file = "pyparsing-3.0.9-py3-none-any.whl", hash = "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"},
|
||||
{file = "pyparsing-3.0.9.tar.gz", hash = "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb"},
|
||||
|
||||
@@ -19,6 +19,7 @@ matplotlib = "3.5.2"
|
||||
scipy = "1.8.1"
|
||||
SQLAlchemy = "1.4.40"
|
||||
black = "22.6.0"
|
||||
PyMySQL = "1.0.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
|
||||
@@ -10,5 +10,4 @@ psycopg2==2.9.3
|
||||
matplotlib==3.5.2
|
||||
sqlalchemy==1.4.40
|
||||
pymysql==1.0.2
|
||||
# Dev
|
||||
black==22.6.0
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
# Library imports
|
||||
from cmath import exp
|
||||
from datetime import datetime
|
||||
from select import select
|
||||
import string
|
||||
from time import ctime
|
||||
import mysql.connector
|
||||
import psycopg2
|
||||
import pandas as pd
|
||||
@@ -94,10 +91,10 @@ class homedb:
|
||||
return df
|
||||
|
||||
def connect_external_db(self):
|
||||
host = "thesillyhomedb.cluster-cdioawtidgpj.eu-west-2.rds.amazonaws.com"
|
||||
host = "thesillyhomedb-instance-1.cdioawtidgpj.eu-west-2.rds.amazonaws.com"
|
||||
port = 3306
|
||||
user = "thesillyhome_general"
|
||||
password = "has123:ASldfa.$"
|
||||
password = "aspperqj14827"
|
||||
database = "thesillyhomedb"
|
||||
extdb = create_engine(
|
||||
f"mysql+pymysql://{user}:{password}@{host}:{port}/{database}", echo=False
|
||||
@@ -108,14 +105,13 @@ class homedb:
|
||||
|
||||
user_id, last_update_time = self.get_user_info()
|
||||
df["user_id"] = user_id
|
||||
|
||||
logging.info(last_update_time)
|
||||
df = df[df["last_updated"] > last_update_time]
|
||||
if not df.empty:
|
||||
df.to_sql(name="states", con=self.extdb, if_exists="append")
|
||||
logging.info(f"Data updloaded.")
|
||||
|
||||
c_time = df["last_updated"].max()
|
||||
self.update_last_update_time(user_id, c_time)
|
||||
max_time = df["last_updated"].max()
|
||||
self.update_last_update_time(user_id, max_time)
|
||||
|
||||
def get_user_info(self):
|
||||
# here we use the mac address as a dummy, this is used for now until an actual login system
|
||||
@@ -135,8 +131,16 @@ class homedb:
|
||||
if len(myresult) == 1:
|
||||
last_update_time = myresult[0][0]
|
||||
else:
|
||||
# Add user if none
|
||||
|
||||
last_update_time = datetime(1900, 1, 1, 0, 0, 0, 0)
|
||||
|
||||
query = f"INSERT INTO thesillyhomedb.users (user_id,last_update_time)\
|
||||
VALUES ('{user_id}','{last_update_time}');"
|
||||
with self.extdb.connect() as connection:
|
||||
connection.execute(query)
|
||||
|
||||
|
||||
return user_id, last_update_time
|
||||
|
||||
def update_last_update_time(self, user_id: string, c_time: datetime):
|
||||
|
||||
Reference in New Issue
Block a user