def getStocksByKey(keyword): result = [] try: conn = sqlite3.connect(DB_NAME) # print("getStocks connect db successfully") cur = conn.cursor() cur.execute("select * from stock where name like ? or code=?",('%'+keyword+'%',keyword,)) items = cur.fetchall() for item in items: stock = Stock() stock.code = item[0] stock.name = item[1] stock.prefix = item[2] result.append(stock) except Exception as e: currentLogger.error("%s",e) finally: if cur!=None: cur.close() if conn!=None: conn.close() return result
currentLogger.error("%s",e) finally: if cur!=None: cur.close() if conn!=None: conn.close() return result[::-1] if __name__ == "__main__": from model import Stock, Daily stock = Stock() stock.name = "美的集团" stock.code = "000333" stock.prefix = "sz" insertStock(stock) daily = Daily() daily.code = "000333" daily.date = "2021-02-10" daily.open = "102.9" daily.last_close = "101.7" daily.current = "107.2" daily.high = "108" daily.low = "101.5" daily.quantity = "8654778686" daily.amount = "1545678968498786.01" daily.bid1 = "107.1" daily.bid2 = "107.0" daily.bid3 = "106.9"