add arguments for input and output file
This commit is contained in:
parent
adf7df9b9b
commit
92fbaf3ceb
|
@ -1,13 +1,22 @@
|
|||
import numpy as np
|
||||
from datetime import datetime
|
||||
import time
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description='Copys, renames and fixes logfiles written by bobbycar sd logger.')
|
||||
parser.add_argument('input', type=argparse.FileType('r'))
|
||||
parser.add_argument('output', nargs='?', type=argparse.FileType('w'))
|
||||
args = parser.parse_args()
|
||||
|
||||
ok=True
|
||||
|
||||
inputFilename='LOG00251.TXT'
|
||||
inputFilename=args.input.name
|
||||
outputFilename=None
|
||||
if args.output is not None:
|
||||
outputFilename=args.output.name
|
||||
|
||||
|
||||
print("Filename: "+str(inputFilename))
|
||||
print("Input Filename: "+str(inputFilename))
|
||||
|
||||
with open(inputFilename, 'r') as reader:
|
||||
lines = reader.readlines()
|
||||
|
@ -34,7 +43,7 @@ linesSize = [len(x.split(',')) for x in lines] #count arraysize for every datali
|
|||
linesOK = np.array(linesSize)==headerSize #mask for okay lines (valid for data lines)
|
||||
|
||||
timestamp=int(lines[0].split('TIMESTAMP:')[1]) #timestamp when file was created
|
||||
#outputFilename=
|
||||
|
||||
|
||||
|
||||
print("Found "+str(len(lines))+" lines")
|
||||
|
@ -44,7 +53,8 @@ print(str(len(datalinesOK))+" Datalines OK")
|
|||
print("Header Size is "+str(headerSize))
|
||||
|
||||
filetime = time.strftime('%Y%m%d_%H%M%S', time.localtime(timestamp))
|
||||
outputFilename = filetime+".csv"
|
||||
if outputFilename is None:
|
||||
outputFilename = filetime+".csv"
|
||||
|
||||
#is_dst(datetime(2019, 4, 1), timezone="US/Pacific")
|
||||
print("Timestamp:"+str(timestamp)+" -> "+str(filetime))
|
||||
|
@ -55,13 +65,16 @@ print("Local Time:"+time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timest
|
|||
print("Writing to: "+str(outputFilename))
|
||||
|
||||
linesWritten = 0
|
||||
with open(outputFilename, 'w') as writer:
|
||||
for i,line in enumerate(lines):
|
||||
if i!=0 and (commentlines[i] or linesOK[i]):
|
||||
writer.write(line+"\n")
|
||||
linesWritten+=1
|
||||
else:
|
||||
print("Skipped "+str(i)+": "+str(line))
|
||||
|
||||
print(str(linesWritten)+" lines written to "+str(outputFilename))
|
||||
if ok:
|
||||
with open(outputFilename, 'w') as writer:
|
||||
for i,line in enumerate(lines):
|
||||
if i!=0 and (commentlines[i] or linesOK[i]):
|
||||
writer.write(line+"\n")
|
||||
linesWritten+=1
|
||||
else:
|
||||
print("Skipped "+str(i)+": "+str(line))
|
||||
|
||||
print(str(linesWritten)+" lines written to "+str(outputFilename))
|
||||
else:
|
||||
print("Failed!")
|
||||
|
||||
|
|
Loading…
Reference in New Issue