Skip to content

Instantly share code, notes, and snippets.

@mutsuda
Created December 25, 2011 10:55

Revisions

  1. mutsuda created this gist Dec 25, 2011.
    32 changes: 32 additions & 0 deletions parser.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # 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!"