parser.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
from openpyxl import Workbook
from openpyxl.drawing.image import Image
from openpyxl.styles import Alignment
from openpyxl.utils import get_column_letter
def morfFileToExcel(fileContent, filePath):
print("Morfing file to excel started")
wb = Workbook()
ws = wb.active
rows = fileContent.split('}}')
ws.column_dimensions['A'].width = 25
ws.cell(column=1, row=1, value='Date')
ws.cell(column=2, row=1, value='Time')
ws.cell(column=3, row=1, value='IP')
ws.cell(column=4, row=1, value='Type')
ws.cell(column=5, row=1, value='User ID')
ws.cell(column=6, row=1, value='Task ID')
ws.cell(column=7, row=1, value='Code')
idx = 2
for row in rows[0:-1]:
tmp0 = row.split(' ', 5)
tmp1 = tmp0[2].split('\t')
total = tmp0[0: 2] + tmp1 + tmp0[3:]
total[6] = total[6][2:]
ws.cell(column=1, row=idx, value=total[0])
ws.cell(column=2, row=idx, value=total[1])
ws.cell(column=3, row=idx, value=total[2])
ws.cell(column=4, row=idx, value=total[3])
ws.cell(column=5, row=idx, value=total[4])
ws.cell(column=6, row=idx, value=total[5])
ws.cell(column=7, row=idx, value=total[6])
idx += 1
exportFile = filePath + '.xlsx'
wb.save(exportFile)
print("Morfing file to excel done, exported file: " + exportFile)