-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_update.py
116 lines (92 loc) ยท 3.27 KB
/
data_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import pandas as pd
import yfinance as yf
from yfinance import shared
from datetime import date, timedelta
import crud
from sqlalchemy.orm import Session
def updates():
#๊ธฐ์กด ๋ฐ์ดํฐ ์ฃผ์ ์
๋ ฅ!!!!
df = pd.read_csv("./preprocessed_data.csv")
# ๋น์ผ ๋ฐ์ดํฐ ์ ์ฅ
yesterday = date.today() - timedelta(1)
date = yesterday.strftime('%Y.%m.%d')
date_for_download = yesterday.strftime('%Y-%m-%d')
li = yf.download(['AAPL', 'AMZN','^IXIC','^NYA','^GSPC','^FTSE','^BSESN','^RUT','000001.SS','CL=F','GC=F','^VIX','DX=F','GOOG','MSFT'],start = date_for_download)
################ error handling
errors = shared._ERRORS
if errors:
print(errors)
if 'AMZN' in errors.keys():
amzn_open = '#N/A'
amzn_High = '#N/A'
amzn_Low = '#N/A'
amzn_Close = '#N/A'
amzn_Volume ='#N/A'
else:
amzn_open = (li['Open']['AMZN'].values)[0]
amzn_High = (li['High']['AMZN'].values)[0]
amzn_Low = (li['Low']['AMZN'].values)[0]
amzn_Close = (li['Close']['AMZN'].values)[0]
amzn_Volume = (li['Volume']['AMZN'].values)[0]
if 'AAPL' in errors.keys():
appl = '#N/A'
else:
appl = (li['Close']['AAPL'].values)[0]
if 'GOOG' in errors.keys():
google = '#N/A'
else:
google = (li['Close']['GOOG'].values)[0]
if '^BSESN' in errors.keys():
bse = '#N/A'
else:
bse = (li['Close']['^BSESN'].values)[0]
if '^GSPC' in errors.keys():
snp = '#N/A'
else:
snp = (li['Close']['^GSPC'].values)[0]
if '^RUT' in errors.keys():
russell = '#N/A'
else:
russell = (li['Close']['^RUT'].values)[0]
if 'CL=F' in errors.keys():
oil = '#N/A'
else:
oil = (li['Close']['CL=F'].values)[0]
if '^IXIC' in errors.keys():
nasdaq = '#N/A'
else:
nasdaq = (li['Close']['^IXIC'].values)[0]
if 'MSFT' in errors.keys():
msft = '#N/A'
else:
msft = (li['Close']['MSFT'].values)[0]
if '^FTSE' in errors.keys():
ftse = '#N/A'
else:
ftse = (li['Close']['^FTSE'].values)[0]
if '^VIX' in errors.keys():
vix = '#N/A'
else:
vix = (li['Close']['^VIX'].values)[0]
if '000001.SS' in errors.keys():
sse = '#N/A'
else:
sse = (li['Close']['000001.SS'].values)[0]
if 'GC=F' in errors.keys():
gold = '#N/A'
else:
gold = (li['Close']['GC=F'].values)[0]
if 'DX=F' in errors.keys():
usd = '#N/A'
else:
usd = (li['Close']['DX=F'].values)[0]
if '^NYA' in errors.keys():
nyse = '#N/A'
else:
nyse = (li['Close']['^NYA'].values)[0]
row = {'Date':date, 'Open':amzn_open, 'High':amzn_High, 'Low':amzn_Low, 'Close':amzn_Close, 'Volume':amzn_Volume, 'NASDAQ':nasdaq, 'NYSE':nyse,'S&P 500':snp, 'FTSE100':ftse, 'BSE SENSEX':bse, 'RUSSELL2000':russell, 'SSE':sse, 'Crude Oil':oil,'Gold':gold, 'VIX':vix, 'USD index':usd, 'Apple':appl, 'Google':google, 'Microsoft':msft}
df=df.append(row, ignore_index=True)
crud.create_stock(db: Session, price: float(amzn_Close))
#์ ์ฅํ๊ณ ์ถ์ ํ์ผ ์ด๋ฆ ์ ์ฅ
df.to_csv('./preprocessed_data.csv',index = False)
return row