Created
December 25, 2011 10:55
Whatsapp conversation parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Position where the first character of a name is found in each line | |
start = 19 | |
# File containing the watsapp conversation | |
file_name = "watext.txt" | |
def get_name(line): | |
end = line.find(":", start) | |
return line[start:end] | |
def get_text(line): | |
end = line.find(":", start) | |
return line[end+2:len(line)] | |
def check_special(line): | |
if ((line.find("joined") != -1) or (line.find("changed subject") != -1)): | |
return 1 | |
else: | |
return 0 | |
print "Processing file..." | |
now = datetime.datetime.now() | |
whatsapp = open(file_name, "r") | |
for line in whatsapp: | |
if not check_special(line) and (re.search("../../.. ..:..:..:", line)): | |
if not os.path.exists("words/"+get_name(line)): | |
os.makedirs("words/"+get_name(line)) | |
file = open("words/"+get_name(line)+"/"+str(now), "a") | |
file.write(get_text(line)) | |
print "Done! Go to the words folder!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment