Created
June 6, 2016 16:57
-
-
Save HackToHell/d694331f58fca6cc093dcf05cd578794 to your computer and use it in GitHub Desktop.
Makes the text into a csv
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
fp = open('C:/Users/Gowtham/Downloads/WhatsApp Chat with xxxx.txt','r') | |
text = fp.readlines() | |
text = [line.rstrip('\n') for line in text] | |
import csv | |
with open('names.csv', 'w') as csvfile: | |
fields = ['time','Name','Text'] | |
writer = csv.DictWriter(csvfile, fieldnames=fields) | |
writer.writeheader() | |
for line in text: | |
try: | |
writer.writerow({'time':line.split('-')[0], 'Name' : line.split('-')[1].split(':')[0] , 'Text' : line.split('-')[1].split(':',1)[1]}) | |
except Exception as e: | |
print line | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment