def create_table(economic_indicator): db_filename = EconomicIndicatorDatabase.db_filename(economic_indicator) schema = """create table {economic_indicator} ( date int primary key not null, expect text, result text );""".format(economic_indicator=economic_indicator) DB.create_table(db_filename, schema)
def insert(economic_indicator, data): db_filename = EconomicIndicatorDatabase.db_filename(economic_indicator) def func(connect): for date, value in data.items(): sql_cmd = """ insert into {economic_indicator} (date, expect, result) values ('{date}', '{expect}', '{result}') """.format(economic_indicator=economic_indicator, date="".join(date.split("/")), expect=value['expect'], result=value["result"]) Log.info("sql_cmd: " + sql_cmd) connect.execute(sql_cmd) DB.execute(db_filename,func)