-
Notifications
You must be signed in to change notification settings - Fork 17
/
convertWod.py
57 lines (52 loc) · 1.61 KB
/
convertWod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
Created on Dec 22, 2017
@author: chris
'''
import sys
import os
import glob
import errno
from shutil import copyfile
def processLog(log):
print(" processing: " + log + " ...")
excludeList = [5,6,7]
includeValues = ['NULL', '-999', '-998', '-997']
firstRun = True
copyfile(log, log + ".bak")
with open(log + ".bak", "r") as f:
for line in f:
fields = line.split(',')
# next check the format
if fields[excludeList[0]] in includeValues or '.' in fields[excludeList[0]]:
if firstRun:
newLog = open(log, "w")
firstRun = False
for x in range(0, len(fields)-1):
if (x not in excludeList):
newLog.write(fields[x] + ",")
newLog.write(fields[len(fields)-1])
else:
print(" skipping, already processed")
f.close()
os.remove(log + ".bak")
return
if not firstRun:
newLog.close()
f.close()
os.remove(log + ".bak")
def convertLogs(dir, match):
logs = glob.glob(dir + os.sep + match)
if len(logs) == 0:
print ('No log files found in ' + dir + ' for ' + match)
for item in logs:
log = os.path.basename(item)
processLog(item)
def main():
if len(sys.argv) <= 1:
print("Usage: convert <FOXDB path>")
sys.exit(1)
dir = sys.argv[1]
print("Converting WOD files to v1.06e format")
convertLogs(dir, "Fox5wodtelemetry*.log")
convertLogs(dir, "Fox5wodradtelemetry*.log")
main()