Commit 4594af0a authored by Markus Mößler's avatar Markus Mößler
Browse files

tried some other updates

parent 6920c56c
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import pandas as pd
import yfinance as yf
from sqlalchemy import create_engine, text
from dotenv import load_dotenv
from sqlalchemy.exc import OperationalError

load_dotenv()

@@ -10,7 +11,10 @@ DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://postgres:postgres@localho
engine = create_engine(DATABASE_URL)

def init_db():
    with engine.connect() as conn:
    retries = 10
    for i in range(retries):
        try:
            with engine.begin() as conn:  # << ensures auto-commit
                conn.execute(text("""
                    CREATE TABLE IF NOT EXISTS nvda_stock (
                        date DATE PRIMARY KEY,
@@ -21,6 +25,14 @@ def init_db():
                        volume BIGINT
                    )
                """))
                print("✅ Table nvda_stock ensured.")
                break
        except Exception as e:
            print(f"❌ Failed to initialize DB (attempt {i+1}/{retries}): {e}")
            time.sleep(2)
    else:
        raise Exception("❌ Could not initialize database after retries.")


def store_nvda_data():
    df = yf.Ticker("NVDA").history(period="5y")
+1 −1

File changed.

Contains only whitespace changes.