Dec-18-2019, 09:09 AM
Hi folks,
I'm new to Python and trying several little projects to get into the languange.
I have a text file which was exported from a WhatsApp chat group and I try to convert this file line by line to a csv format:
23.11.19, 21:35 - Person A: ndsnldkl odj aso saod saodjd ad?
23.11.19, 21:43 - Person B: nsidd dsidaojd eduq dsajojdipajd adapsd??
23.11.19, 21:44 - Person C: ahush asaosi0sj a0s9uaS SJs !!
The output is a csv format:
23.11.19;21:35;Person A;ndsnldkl odj aso saod saodjd ad?
Thats my (newbie) code:
29.11.19, 15:54 - Person D: ndadad saojd sapods dsap.
ksjd sad aslajd a
The "message = x[pos1+2:-1]" does not recognize the line break.
I had written this code in the past with PHP that works nearly the same, but PHP recognizes the full message including the line breaks.
Any idea how I can fix that?
Greetings,
Daniel
I'm new to Python and trying several little projects to get into the languange.
I have a text file which was exported from a WhatsApp chat group and I try to convert this file line by line to a csv format:
23.11.19, 21:35 - Person A: ndsnldkl odj aso saod saodjd ad?
23.11.19, 21:43 - Person B: nsidd dsidaojd eduq dsajojdipajd adapsd??
23.11.19, 21:44 - Person C: ahush asaosi0sj a0s9uaS SJs !!
The output is a csv format:
23.11.19;21:35;Person A;ndsnldkl odj aso saod saodjd ad?
Thats my (newbie) code:
liste = [] for x in f: date = x[:8] time = x[10:15] pos1 = x.find(":",18,-1) name = x[18:pos1] message = x[pos1+2:-1] liste.append(date) liste.append(time) liste.append(name) liste.append(message)It works great until I get messages like this with line break:
29.11.19, 15:54 - Person D: ndadad saojd sapods dsap.
ksjd sad aslajd a
The "message = x[pos1+2:-1]" does not recognize the line break.
I had written this code in the past with PHP that works nearly the same, but PHP recognizes the full message including the line breaks.
Any idea how I can fix that?
Greetings,
Daniel