-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtils.py
44 lines (36 loc) · 1.23 KB
/
Utils.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
import json
import csv
import os
import yaml
import glob
def getJsonFromFile(filePath):
with open(filePath, "r") as file:
jsonData = json.loads(file.read())
return jsonData
def getCSVFromFile(filePath):
with open(filePath, "r") as file:
csvData = csv.reader(file)
csvHeaders = next(csvData)
csvRows = []
for row in csvData:
csvRows.append(row)
return csvHeaders, csvRows
def writeCSVFile(filePath="",writeMode ="w", Headers = "", Rows=""):
with open(filePath, writeMode, newline='', encoding='UTF8') as file:
csvWriter = csv.writer(file)
if Headers != "":
csvWriter.writerow(Headers)
if Rows != "":
csvWriter.writerows(Rows)
def getYamlFromFile(filePath):
with open(filePath, "r") as file:
return yaml.safe_load_all(file.read())
def getFilePathsRecursively(folderPath, extension):
print("\nRules Path: " + os.path.join(folderPath, '**\*.') + extension)
return list(glob.iglob(os.path.join(folderPath, '**/*.') + extension, recursive=True))
def convert_timestamp(datetime_obj):
try:
ret = datetime_obj.strftime('%Y-%m-%d-%H:%M:%S')
except ValueError:
ret = '00000000-000000'
return ret