add arguments for input and output file
This commit is contained in:
parent
adf7df9b9b
commit
92fbaf3ceb
|
@ -1,13 +1,22 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
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
|
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:
|
with open(inputFilename, 'r') as reader:
|
||||||
lines = reader.readlines()
|
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)
|
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
|
timestamp=int(lines[0].split('TIMESTAMP:')[1]) #timestamp when file was created
|
||||||
#outputFilename=
|
|
||||||
|
|
||||||
|
|
||||||
print("Found "+str(len(lines))+" lines")
|
print("Found "+str(len(lines))+" lines")
|
||||||
|
@ -44,6 +53,7 @@ print(str(len(datalinesOK))+" Datalines OK")
|
||||||
print("Header Size is "+str(headerSize))
|
print("Header Size is "+str(headerSize))
|
||||||
|
|
||||||
filetime = time.strftime('%Y%m%d_%H%M%S', time.localtime(timestamp))
|
filetime = time.strftime('%Y%m%d_%H%M%S', time.localtime(timestamp))
|
||||||
|
if outputFilename is None:
|
||||||
outputFilename = filetime+".csv"
|
outputFilename = filetime+".csv"
|
||||||
|
|
||||||
#is_dst(datetime(2019, 4, 1), timezone="US/Pacific")
|
#is_dst(datetime(2019, 4, 1), timezone="US/Pacific")
|
||||||
|
@ -55,6 +65,7 @@ print("Local Time:"+time.strftime('%A, %Y-%m-%d %H:%M:%S', time.localtime(timest
|
||||||
print("Writing to: "+str(outputFilename))
|
print("Writing to: "+str(outputFilename))
|
||||||
|
|
||||||
linesWritten = 0
|
linesWritten = 0
|
||||||
|
if ok:
|
||||||
with open(outputFilename, 'w') as writer:
|
with open(outputFilename, 'w') as writer:
|
||||||
for i,line in enumerate(lines):
|
for i,line in enumerate(lines):
|
||||||
if i!=0 and (commentlines[i] or linesOK[i]):
|
if i!=0 and (commentlines[i] or linesOK[i]):
|
||||||
|
@ -64,4 +75,6 @@ with open(outputFilename, 'w') as writer:
|
||||||
print("Skipped "+str(i)+": "+str(line))
|
print("Skipped "+str(i)+": "+str(line))
|
||||||
|
|
||||||
print(str(linesWritten)+" lines written to "+str(outputFilename))
|
print(str(linesWritten)+" lines written to "+str(outputFilename))
|
||||||
|
else:
|
||||||
|
print("Failed!")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue