Skip to content

Commit

Permalink
分时导入增加保护
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Jan 4, 2022
1 parent 50797b1 commit 2fa556a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions hikyuu/data/pytdx_to_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import sqlite3
from pytdx.hq import TDXParams

from hikyuu.util.mylog import hku_error
from hikyuu.util.mylog import hku_error, hku_info

from .common import MARKETID, STOCKTYPE, get_stktype_list
from .common_sqlite3 import (
Expand Down Expand Up @@ -434,19 +434,25 @@ def import_on_stock_time(connect, api, h5file, market, stock_record, max_days):

stockid, marketid, code, valid, stktype = stock_record[0], stock_record[1], stock_record[2], stock_record[3], \
stock_record[4]
hku_info("{}{}".format(market, code))
table = get_time_table(h5file, market, code)
if table is None:
hku_error("Can't get table({}{})!".format(market, code))
return 0

today = datetime.date.today()
if table.nrows > 0:
last_datetime = int(table[-1]['datetime'] // 10000)
last_y = int(last_datetime // 10000)
last_m = int(last_datetime // 100 - last_y * 100)
last_d = int(last_datetime - (last_y * 10000 + last_m * 100))
last_date = datetime.date(last_y, last_m, last_d)
need_days = (today - last_date).days
try:
last_datetime = int(table[-1]['datetime'] // 10000)
last_y = int(last_datetime // 10000)
last_m = int(last_datetime // 100 - last_y * 100)
last_d = int(last_datetime - (last_y * 10000 + last_m * 100))
last_date = datetime.date(last_y, last_m, last_d)
need_days = (today - last_date).days
except Exception as e:
hku_error("Failed get last date from hdf5({}{}), remove this table! {}".format(market, code, e))
table.remove()
return 0
else:
need_days = max_days

Expand Down

0 comments on commit 2fa556a

Please sign in to comment.