I have this csv with a bunch of emails that I want to parse, uploaded here
Using this library and thanks to this answer, we have this loop that would go over the CSV and apply the cleaning function EmailReplyParser.parse_reply(email_message) to each message:
from email_reply_parser import EmailReplyParser
import csv
with open('D:/Harry_Potter.csv', encoding="utf8") as inf:
reader = csv.reader(inf.readlines())
with open('D:/clean.csv', 'w') as outf:
writer = csv.writer(outf)
# need to skip the title
title = reader.__next__()
for row in reader:
EmailReplyParser.parse_reply(row[0].split()[-1])
writer.writerows(reader)
However, this does not work.
It loops just fine, but emails are not cleaned. When I try it with a single message copy pasted from the CSV,
email = """I don't have an owl
On Saturday 18 June 2016, Hogwarts School of Witchcraft and Wizardry <
no-reply@wufoo.com> wrote:
> HOGWARTS SCHOOL of WITCHCRAFT and WIZARDRY
>
> Headmaster: Albus Dumbledore
> (Order of Merlin, First Class, Grand Sorc., Chf. Warlock,
> Supreme Mugwump, International Confed. of Wizards)
>
> Dear Student,
>
> We are pleased to inform you that you have been accepted at Hogwarts
> School of Witchcraft and Wizardry. Please find enclosed a list of all
> necessary books and equipment.
>
> Term begins on 1 September. We await your owl by no later than 31 July.
>
>
> Yours sincerely,
>
> [image: image]
>
> Minerva McGonagall
>
> Deputy Headmistress
>
> Here is your ticket for the Hogwarts Express:
>
> [image: image]
>"""
It gives me the right result, like so:
EmailReplyParser.parse_reply(email)
Out[11]: "I don't have an owl"
Why is the CSV not being read correctly? (I've uploaded the CSV so that it can be tried without downloading).