Finalize the finance cache puller

This commit is contained in:
2026-02-11 20:14:56 -08:00
parent 777483f8bf
commit b81f26daa8
2 changed files with 35 additions and 33 deletions
+27
View File
@@ -0,0 +1,27 @@
import sqlite3
class DataBase:
def __init__(self):
# Initilize SqLite
self.conn = sqlite3.connect("./data/appdata.db")
self.cursor = self.conn.cursor()
# Create keystore table if it doesnt exist already
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS keystore (
key TEXT PRIMARY KEY,
value TEXT
)
''')
# Set a key in the keystore
def SetKey(self, Key, Value):
self.cursor.execute('INSERT OR REPLACE INTO keystore (key, value) VALUES (?, ?)', (Key, Value))
self.conn.commit()
# Get a key from the keystore
def GetKey(self, Key):
self.cursor.execute('SELECT value FROM keystore WHERE key = ?', (Key, ))
result = self.cursor.fetchone()
return result[0] if result else None
+8 -33
View File
@@ -1,45 +1,20 @@
import sqlite3
from datetime import date, datetime from datetime import date, datetime
from datapuller import DataPuller from datapuller import DataPuller
from database import DataBase
def main(): def main():
# Initilize SqLite
dbconn = sqlite3.connect("./data/appdata.db")
dbcursor = dbconn.cursor()
# Create keystore table if it doesnt exist already # Load the database object
dbcursor.execute(''' db = DataBase()
CREATE TABLE IF NOT EXISTS keystore (
key TEXT PRIMARY KEY,
value TEXT
)
''')
def SetKey(Key, Value): # If we havent already pulled the stock data today
dbcursor.execute('INSERT OR REPLACE INTO keystore (key, value) VALUES (?, ?)', (Key, Value)) if db.GetKey("LastRun") != str(date.today()):
dbconn.commit() # Update the data store in the data folder
def GetKey(Key):
dbcursor.execute('SELECT value FROM keystore WHERE key = ?', (Key, ))
result = dbcursor.fetchone()
return result[0] if result else None
# Pull the last run data
lastrundata = GetKey("LastRun")
lastrun = None
if lastrundata != None:
lastrun = datetime.strptime( lastrundata, "%Y-%m-%d" )
else:
lastrun = datetime.strptime( "2000-01-01", "%Y-%m-%d" )
# If the strings dont match becuase were only checking day it has to be a new day so update the data
if lastrun != str(date.today()):
# This will update the data store in the data folder
DataPuller.pull() DataPuller.pull()
# Update the last run to today # Update the last run to today
SetKey("LastRun", str(date.today())) db.SetKey("LastRun", str(date.today()))
# Load in the AI algorithm late so yfinance works properly # Lazy Load in the AI algorithms so yfinance works properly
import tensorflow as tf import tensorflow as tf
import keras import keras
from keras.layers import Dense, Flatten, Conv2D from keras.layers import Dense, Flatten, Conv2D