-
Notifications
You must be signed in to change notification settings - Fork 557
/
zh_bond10_to_sqlite.py
42 lines (36 loc) · 1.15 KB
/
zh_bond10_to_sqlite.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
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# Create on: 2024-03-01
# Author: fasiondog
import datetime
from hikyuu.data.common import get_china_bond10_rate
from hikyuu.util import *
@hku_catch(trace=True)
def import_zh_bond10_to_sqlite(connect):
sql = "select max(date) from zh_bond10"
cur = connect.cursor()
cur.execute(sql)
a = cur.fetchall()
if a[0][0] is None:
start_date = "19901219"
else:
last_date = a[0][0]
year = last_date // 10000
month = last_date // 100 - year * 100
day = last_date - year * 10000 - month * 100
start_date = (datetime.date(year, month, day) + datetime.timedelta(1)).strftime('%Y%m%d')
rates = get_china_bond10_rate(start_date)
if rates:
cur.executemany("INSERT INTO zh_bond10(date, value) VALUES (?, ?)", rates)
connect.commit()
cur.close()
if __name__ == '__main__':
import os
import sqlite3
from hikyuu.data.common_sqlite3 import create_database
db = "d:\\workspace\\hikyuu\\test_data\\stock.db"
connect = sqlite3.connect(db)
create_database(connect)
import_zh_bond10_to_sqlite(connect)
connect.close()