July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.
import os, time from datetime import datetime, timedelta def SpecErrLog(File, dt, err, Duration): source_file = open(File,"r") try: file1 = File + " " + dt.replace(":","_") + " [" + err + "]" + str(Duration) #file1 = "temptry.txt" dest_file = open(file1, 'w') Mach, Dt = File.split() BeginDay = datetime.strptime("00:00:00.000", '%H:%M:%S.%f') EndDay = datetime.strptime("23:59:59.999", '%H:%M:%S.%f') dt = datetime.strptime(dt, '%H:%M:%S.%f') for line in source_file: arr=line.split(",") LineTimeStamp = datetime.strptime(arr.strip(), '%H:%M:%S.%f') #timeStamp of sourcefile. upperLimit= dt + timedelta(minutes=Duration) lowerLimit= dt - timedelta(minutes=Duration) if lowerLimit > BeginDay and upperLimit < EndDay: #if all records accurr within the same day. if lowerLimit < LineTimeStamp < upperLimit: dest_file.write(line) finally: source_file.close dest_file.close print "finished" if __name__ == "__main__": dt = "09:52:15.710" err = "54300" SpecErrLog("H108 01-24-2011", dt, err, 30)
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.