forked from GSA/SF-Event-Monitoring-Log-Retrieval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileWriter.py
23 lines (19 loc) · 936 Bytes
/
FileWriter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import datetime
import re
class FileWriter:
path = ''
global strLogDateTime
global strFormatedLogDateTime
def __init__(self, eventLogFile, sfURL):
# self.path = 'data/'+sfURL+'/'+eventLogFile["EventType"]+'/'+eventLogFile["LogDate"]+'_'+eventLogFile["Id"]+'.csv'
strLogDateTime = eventLogFile["LogDate"]
strFormatedLogDateTime = str(datetime.datetime.strptime(strLogDateTime[0:19],"%Y-%m-%dT%H:%M:%S"))
strFormatedLogDateTime = re.sub('[^a-zA-Z0-9 \n\.\-]', '', strFormatedLogDateTime).replace(" ", "_")
self.path = 'data/'+sfURL+'/'+eventLogFile["EventType"]+'/'+strFormatedLogDateTime+'_'+eventLogFile["Id"]+'.csv'
print(self.path)
if not os.path.exists(os.path.dirname(self.path)):
os.makedirs(os.path.dirname(self.path))
def writeFile(self, input):
with open(self.path, 'w') as file:
file.write(str(input))