-
Notifications
You must be signed in to change notification settings - Fork 0
/
importCSVfolder.py
executable file
·67 lines (52 loc) · 2.56 KB
/
importCSVfolder.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
58
59
60
61
62
63
64
65
#!/usr/bin/python
# Single run of script, possibly used with cron trigger.
# Keeps file comparison and uploads new files
import argparse
import json
import minotaur
from processlib import csvToInfluxdb
from processlib import hashDir
from processlib import preProcess
def startup(inputfiles, watch, config, hashstore, preprocess):
if watch:
folderwatch(inputfiles, config, hashstore, preprocess)
else:
runImport(inputfiles, config, hashstore, preprocess)
def runImport(inputfiles, config, hashstore, preprocess):
filelist = []
filelist = hashDir.getNewFiles(inputfiles, hashstore) #checks is there is any changed files and return a list
if preprocess: #probably not usable for any one but me, but this is how I'm allowing modability to my scripts
print("PreProcess selected")
filelist = preProcess.removeUnwanted(filelist) #removes files, based on a set phrase, from the file list.
for i in filelist: #[i = HASH, Full path to file, filename]
jsonblob = preProcess.runPreProcess(i[2], config)
csvToInfluxdb.loadCsv(i[1], jsonblob) #passes the the json object into the csv import script
else:
for i in filelist: #[i = HASH, Full path to file, filename]
csvToInfluxdb.loadConfig(i[1], config)
print("Import Done")
def folderwatch(inputfiles, config, hashstore, preprocess):
runImport(inputfiles, config, hashstore, preprocess)
with minotaur.Inotify() as n:
n.add_watch('sample', minotaur.Mask.CLOSE_WRITE)
try:
for evt in n:
#print(evt)
runImport(inputfiles, config, hashstore, preprocess)
except KeyboardInterrupt:
print(' stopped')
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='csv to influxdb')
parser.add_argument('-i', '--input', nargs='?', required=True,
help='Input folder to consume')
parser.add_argument('-w', '--watch', nargs='?', default=False,
help='enable folder watch')
parser.add_argument('-c', '--config', nargs='?', default='csv.json',
help='config file location')
parser.add_argument('-s', '--hashstore', nargs='?', default='.hashstore',
help='hashed file store')
parser.add_argument('-p', '--preprocess', nargs='?', default=False,
help='enable use of preprocessing script')
args = parser.parse_args()
startup(args.input, args.watch, args.config, args.hashstore, args.preprocess)