-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparser.py
More file actions
34 lines (29 loc) · 925 Bytes
/
parser.py
File metadata and controls
34 lines (29 loc) · 925 Bytes
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
import re
import sys
class WhatsappChatParser(object):
def __init__(self, chatFile):
self.chatFile = chatFile
self.counter = 0
def process(self):
chatFile = open(self.chatFile, 'r')
lineBuffer = ""
cleanFile = open("cleanFile.txt","w")
for line in chatFile:
line = line.rstrip()
if (self.isNewRecord(line)):
cleanFile.write(lineBuffer+"\n")
cleanFile.write(line)
lineBuffer = ""
else:
lineBuffer = lineBuffer + " " + line
print self.counter
self.counter = self.counter + 1
cleanFile.close()
print "done"
def isNewRecord(self, line):
if (re.match('^(\d{1,2})[/.-](\d{1,2})[/.-](\d{4})',line.strip()) is not None):
return True
else:
return False
ChatParser = WhatsappChatParser('srimulat.txt');
ChatParser.process()