import mysql.connectordef Main(): #云量数据库 db = mysql.connector.connect(user=‘check_user‘,password=‘654321123456‘,port=3306,host=‘123.56.72.57‘,db=‘test_check‘) # 连接mysql # 获取游标 cursor = db.cursor() #查询表的字段 sql = ‘select * from stock_kline WHERE tr_date=20161214 and date_type=0 and ex_type=1‘ # 执行sql语句 cursor.execute(sql) #接受返回结果 rows = cursor.fetchall() #循环找出high和low的位置 for i in rows: # print(i) maxs = i[9] mins = i[10] # 判断这个公式 if (maxs - mins) / mins * 100 > 10: xg = (maxs - mins) / mins * 100 print(i[1], i[2], i[4], i[5], xg, i[-2], i[-1]) #sql语句写入数据库,由于表的问题,重新建立一个表opop,里面字段和原表字段一样 sql1 = ‘insert into opop(`code`,`tr_date`,`date_type`,`ex_type`,`xg`,`remark`,`time`) VALUES ("%s","%s","%s","%s","%s","%s","%s")‘ % (i[1], i[2], i[4], i[5], xg, i[-2], i[-1]) cursor.execute(sql1) #提交 db.commit()#调用执行函数if __name__ == "__main__": Main()
时间: 2024-10-13 00:48:33