Skip to content

Instantly share code, notes, and snippets.

@HackToHell
Created June 6, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HackToHell/d694331f58fca6cc093dcf05cd578794 to your computer and use it in GitHub Desktop.
Save HackToHell/d694331f58fca6cc093dcf05cd578794 to your computer and use it in GitHub Desktop.
Makes the text into a csv
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