# Take a file of many expiration dates separated by a single line # with something like tmpDATE (e.g. tmp12_31_2021) # Then call each one, copy it to tmp and run bit.py all going to tmpout. import csv import os from datetime import date today = date.today() d2 = today.strftime("%B %d, %Y") os.system("echo " + d2 + " >> tmpinall") os.system("cat tmpin >> tmpinall") os.system("cat tmpin |grep -v 'in-the-money' | grep -v 'not suitable' |grep -v 'Before investing' |grep -v 'Client Agreement' | grep -v 'Unauthorized' > tmpin2") # os.system("echo 'BITO ' >> tmpin2") filein = open("tmpin2","r") text = filein.readlines() filein.close() os.system("echo " + d2 + " > tmp.out") bitocount = 0 newtext = [] currentprice = -1000.0 for line in text: x = line.split(" ") y = line.split(" ") if (x[0] == "BITO") or (y[0] == "BITO"): # print("BITO line: " + line) bitocount+=1 # print("bitocount: " + str(bitocount)) if bitocount == 1: # where we get the current price # print(" y[0] is: " + y[0] + " y[1] is: " + y[1]+ " y[2] is: " + y[2]+ " y[3] is: " + y[3]+ " y[4] is: " + y[4]+ " y[5] is: " + y[5]) currentprice = (float(y[3])+ float(y[5]))/2.0 currentprice = round(currentprice,2) os.system("echo current price is: " + str(currentprice) + " >> tmp.out") # print("current price is: " + str(currentprice)) elif bitocount>= 3: # first time there is a complete file with open(filename, "wt", encoding='utf-8') as myfile: for newlines in newtext: print(newlines, file = myfile) myfile.close os.system(" echo >> tmp.out") os.system(" echo " + filename[3:] + " >> tmp.out") os.system("./runsed " + filename) os.system("python3 bit.py " + str(currentprice) + " >> tmp.out") filename = ("tmp")+x[1]+("_")+ x[2]+ "_" + x[3][:4] newtext = [] elif bitocount >=2: newtext.append(line) if bitocount>=3: # we have a full file with open(filename, "wt", encoding='utf-8') as myfile: for newlines in newtext: print(newlines, file = myfile) myfile.close