init
This commit is contained in:
@@ -12,9 +12,10 @@ def inserData(symbol, interval, data):
|
||||
conn = sqlite3.connect('coins.db')
|
||||
cursor = conn.cursor()
|
||||
|
||||
tableName = "{}_{}".format(symbol, str(interval))
|
||||
# 테이블/키 생성
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (interval text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, Close REAL, Open REAL, High REAL, Low REAL, Volume REAL)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(interval, CODE, ymdhms)")
|
||||
cursor.execute("CREATE TABLE IF NOT EXISTS {} (CODE text, NAME text, ymdhms datetime, ymd text, hms text, Close REAL, Open REAL, High REAL, Low REAL, Volume REAL)".format(tableName))
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS {}_idx on {}(CODE, ymdhms)".format(tableName, tableName))
|
||||
|
||||
for i in range(len(data)):
|
||||
ymd = data.index[i].strftime('%Y%m%d')
|
||||
@@ -26,12 +27,12 @@ def inserData(symbol, interval, data):
|
||||
Close = data.Close.iloc[i]
|
||||
Volume = data.Volume.iloc[i]
|
||||
|
||||
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
|
||||
cursor.execute("SELECT * from {} where CODE = ? and ymdhms = ?".format(tableName), (symbol, ymdhms, ))
|
||||
arr = cursor.fetchone()
|
||||
if arr:
|
||||
cursor.execute("UPDATE " + symbol + " SET Close=?, Open=?, High=?, Low=?, Volume=? where CODE=? and ymdhms=? and interval=?", (Close, Open, High, Low, Volume, symbol, ymdhms, interval))
|
||||
cursor.execute("UPDATE {} SET Close=?, Open=?, High=?, Low=?, Volume=? where CODE=? and ymdhms=?".format(tableName), (Close, Open, High, Low, Volume, symbol, ymdhms))
|
||||
else:
|
||||
cursor.execute("INSERT INTO " + symbol + " (interval, CODE, NAME, ymdhms, ymd, hms, Close, Open, High, Low, Volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, Close, Open, High, Low, Volume))
|
||||
cursor.execute("INSERT INTO {} (CODE, NAME, ymdhms, ymd, hms, Close, Open, High, Low, Volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)".format(tableName), (symbol, KR_COINS[symbol], ymdhms, ymd, hms, Close, Open, High, Low, Volume))
|
||||
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
@@ -44,9 +45,16 @@ def download():
|
||||
|
||||
# 1시간
|
||||
interval = 60
|
||||
|
||||
data = monitorCoin.get_coin_more_data(symbol, interval, bong_count=10000)
|
||||
if data is not None and not data.empty:
|
||||
try:
|
||||
inserData(symbol, interval, data)
|
||||
except Exception as e:
|
||||
print(f"Error processing data for {symbol}: {str(e)}")
|
||||
|
||||
# 5분
|
||||
interval = 5
|
||||
data = monitorCoin.get_coin_more_data(symbol, interval, bong_count=10000)
|
||||
if data is not None and not data.empty:
|
||||
try:
|
||||
inserData(symbol, interval, data)
|
||||
|
||||
Reference in New Issue
Block a user