import csv import os import re fcsv = open("test.csv", 'w') writer = csv.writer(fcsv) runNumStart = -4 runNumStop = -1 skipID = [11, 12, 29, 36, 208, 296, 297, 298, 299, 300, 301] for elogID in range(2, 583) : continueFlag = False for y in skipID: if( elogID == y ): continueFlag = True break if( continueFlag ): continue runNumber = -4 runStartFlag=False; runStopFlag=False; print("===================================== %d" % elogID) cmd = "elog -h elog.physics.fsu.edu -l elog/2022_05_e21062_FRIB -u GeneralFox fsuphysics888 -w %d > haha.txt" % elogID #print(cmd) os.system(cmd) felog = open("haha.txt", "r") for x in felog : #print(x) posStart = x.find('Type: Run Start') posStop = x.find('Type: Run End') posRunNum = x.find('RunNumber:') if( posStart >= 0 ) : runStartFlag = True if( posStop >= 0 ): runStopFlag = True if( posRunNum >= 0 and (runStartFlag or runStopFlag) ): pos = re.search(r"\d", x) if( pos ): runNumber = int(x[pos.start():-1]) #print("-- Run Number : |%d|" % runNumber) print("RunNumber : %d, start : %d, stop : %d " % (runNumber, runStartFlag, runStopFlag)) if( runNumber == -4 ) : continue if( posStart == False and posStop == False ) : continue msg = x if( runStartFlag ): runNumStart = runNumber dateStart=msg[0:30] #print("|%s|" % dateStart) pos=msg.find('Title:') title=msg[pos+7:-1] #print("|%s|" % title) runStartFlag = False if( runStopFlag ): runNumStop = runNumber dateStop=msg[0:30] #print("|%s|" % dateStop) runStopFlag = False felog.close() if( runNumStart == runNumStop): print([runNumStart, dateStart,dateStop,title]) writer.writerow([runNumStart, dateStart,dateStop,title]) runNumStart = -4 runNumStop = -1 fcsv.close()