import sqlite3 as db
import fn

data_base = db.connect('data_stock')
cursor = data_base.cursor()


# 插入数据库
#
#
#zt_hy stirng 涨停行业排名 如  [1]元器件:5 [2]软件服务:4 [3]食品:2 [4]百货:2 [5]旅游服务:2 [6]广告包装:2 [7]石油开采:2 [8]通信设备:1

def insert_row(time, info,zt_hy):
    cursor.execute('create table if not exists stock_zt(id INTEGER PRIMARY KEY AUTOINCREMENT,date int,info text,zt_hy varchar(256))')
    data_base.commit()

    cursor.execute("insert into stock_zt (date,info,zt_hy) VALUES (%d,'%s','%s')" % (time, info,zt_hy))
    data_base.commit()


def show(desc):
    cursor.execute(" select * from (select * from stock_zt group by info order by id desc limit 50 ) order by id %s" % (desc))
    result = cursor.fetchall()
    for row in result:
        # print("%s %s \r\n %s" %(fn.custom_time(row[1], 2),row[2][0:125],row[3]))
        print("%s %s \r\n \033[0;35;40m%s\033[0m" %(fn.custom_time(row[1], 2),row[2][0:125],row[3]))
