Skip to content

Instantly share code, notes, and snippets.

@mutsuda
Created December 25, 2011 10:55
Show Gist options
  • Save mutsuda/1519092 to your computer and use it in GitHub Desktop.
Save mutsuda/1519092 to your computer and use it in GitHub Desktop.
Whatsapp conversation parser
# 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