Finalize the finance cache puller
This commit is contained in:
+27
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user