|
|
|
|
@ -27,8 +27,13 @@ def update_data(): |
|
|
|
|
# If the latest date is not today, update the data |
|
|
|
|
if latest_date < datetime.date.today(): |
|
|
|
|
df = yf.download(ticker, start=latest_date.strftime('%Y-%m-%d'), |
|
|
|
|
end=datetime.date.today().strftime('%Y-%m-%d'), progress=False) |
|
|
|
|
value = [(ticker, df.index[i], df['Close'][i]) for i in range(len(df))] |
|
|
|
|
end=datetime.date.today().strftime('%Y-%m-%d'), progress=False, threads=False) |
|
|
|
|
if df is None or df.empty: |
|
|
|
|
continue |
|
|
|
|
price_col = 'Close' if 'Close' in df.columns else ('Adj Close' if 'Adj Close' in df.columns else None) |
|
|
|
|
if price_col is None: |
|
|
|
|
continue |
|
|
|
|
value = [(ticker, df.index[i], float(df[price_col].iloc[i])) for i in range(len(df))] |
|
|
|
|
with conn: |
|
|
|
|
with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as curs: |
|
|
|
|
sql = "insert into stock_price (ticker, date, price) values %s" |
|
|
|
|
@ -50,8 +55,13 @@ def update_data_tw(): |
|
|
|
|
# If the latest date is not today, update the data |
|
|
|
|
if latest_date < datetime.date.today(): |
|
|
|
|
df = yf.download(ticker, start=latest_date.strftime('%Y-%m-%d'), |
|
|
|
|
end=datetime.date.today().strftime('%Y-%m-%d'), progress=False) |
|
|
|
|
value = [(ticker, df.index[i], df['Close'][i]) for i in range(len(df))] |
|
|
|
|
end=datetime.date.today().strftime('%Y-%m-%d'), progress=False, threads=False) |
|
|
|
|
if df is None or df.empty: |
|
|
|
|
continue |
|
|
|
|
price_col = 'Close' if 'Close' in df.columns else ('Adj Close' if 'Adj Close' in df.columns else None) |
|
|
|
|
if price_col is None: |
|
|
|
|
continue |
|
|
|
|
value = [(ticker, df.index[i], float(df[price_col].iloc[i])) for i in range(len(df))] |
|
|
|
|
with conn: |
|
|
|
|
with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as curs: |
|
|
|
|
sql = "insert into stock_price_tw (ticker, date, price) values %s" |
|
|
|
|
|