我有一个python程序,它每分钟读取一个二进制文件,包含实时股票市场数据,接受它们的名称作为命令行参数,并将它们的内容写入数据库表。但是,它似乎为每个文件生成相同的输出,而不管其内容是什么,因为每个文件都有不同的值。我能做些什么摆脱这个问题?
谢谢和问候。继承我的代码:
import struct as st
import pymysql
import sys
import os
os.chdir(r'/root/IND')
print("FILE TO BE OPENED:",sys.argv[1]+".ind")
fName=sys.argv[1]+".ind"
print("you want to open",fName)
mkt = open(fName, "rb")
print("Opened",fName)
transcode=5
mlength=78
i=0
while(i<46):
#HEADER DATA
transcode = int.from_bytes(mkt.read(2), byteorder='little')
timestamp = int.from_bytes(mkt.read(4), byteorder='little')
mlength = int.from_bytes(mkt.read(2), byteorder='little')
#BODY DATA
indtok = str(int.from_bytes(mkt.read(2), byteorder='little'))
print("Token: ------------------------",indtok)
iov = int.from_bytes(mkt.read(4), byteorder='little')
civ = str(int.from_bytes(mkt.read(4), byteorder='little'))
print("Value:",civ)
hiv = int.from_bytes(mkt.read(4), byteorder='little')
liv = int.from_bytes(mkt.read(4), byteorder='little')
pc = str(int.from_bytes(mkt.read(4), byteorder='little'))
print("Percentage change:",pc)
ihiv = int.from_bytes(mkt.read(4), byteorder='little')
iliv = int.from_bytes(mkt.read(4), byteorder='little')
ioiv = int.from_bytes(mkt.read(4), byteorder='little')
iciv = int.from_bytes(mkt.read(4), byteorder='little')
filler = int.from_bytes(mkt.read(4), byteorder='little')
#print(i,"--NEXT FILE")
i+=1