sandsturm / whatsapp-converter

Use this application to convert your exported WhatsApp chat to a CSV, Excel or ODS file.
MIT License
17 stars 8 forks source link

Issue on M1 Mac #8

Closed Asad98 closed 3 years ago

Asad98 commented 3 years ago

Hello, thank you so much for this converter, when executing the command I found the following error, please advise on how this can be mitigated

Error: - File "whatsapp_converter.py", line 190 print(f'\n{BCOLORS["FAIL"]}Error: Excel 2003 only supports a maximum of 65535 lines. Whatsapp-converter found more than 65535 lines for input which might lead to an error.{BCOLORS["ENDC"]}\n') ^ SyntaxError: invalid syntax

sandsturm commented 3 years ago

If you really have Excel 2003 there is no way around this. In case you have a newer Excel you can export it to xlsx. Please try whatsapp-converter inputfile.txt outputfile.xlsx

If it does not work, please come back to me.

Asad98 commented 3 years ago

I have the latest version of excel, but unfortunately the above command still doesn't work, if it helps I am listing the steps I did to install the dependencies and the program: 1) I installed xcode first on my mac (Python came along with it) 2) Then I installed pip using get-pip.py using curl 3) Then I installed the dependencies listed on the readme page for the converter, but pip was not recognised for some reason, so I used pip3 and it worked and everything installed 4) Downloaded the source code 5) Extracted it 6) pasted the chat.txt file and the whatsapp_converter.py together and used the command: "python whatsapp_converter.py chat.txt" and the above showed up, also tried your command same result though

Please advise what the issue can be potentially.

Thank you for your help and time

sandsturm commented 3 years ago

I do not have a Mac. So we can give this a try. What you can do: go to the whatsapp-converter.py script and delete lines 186 to 192. This is the code below. Then save it. Make sure you export to xlsx.

#--------------------------------------------- # Select export formats if str(local_args.resultset).endswith('.xls'): if line_count > 65535: print(f'\n{BCOLORS["FAIL"]}Error: Excel 2003 only supports a maximum of 65535 lines. Whatsapp-converter found more than 65535 lines for input which might lead to an error.{BCOLORS["ENDC"]}\n') `` print("") sys.exit()

Asad98 commented 3 years ago

Hello, Many thanks for your support, I did what you asked, however I am facing the following error when executing :-

python whatsapp_converter.py _chat.txt outputfile.xlsx File "whatsapp_converter.py", line 224 print(f'{BCOLORS["WARNING"]}NOTE: The writing of the ODS file takes some time. Your terminal did not crash. Please wait ...{BCOLORS["ENDC"]}') ^ SyntaxError: invalid syntax

When I execute the command - whatsapp-converter inputfile.txt outputfile.xlsx. it doesnt work and gives me the following error: - zsh: command not found: whatsapp-converter

sandsturm commented 3 years ago

Oh, I see. This is due to the color codes in the Linux shell. I will update the program code to not show color codes on Macs. I will work on this today.

Please try: python whatsapp_converter.py chat.txt chat.xlsx

Asad98 commented 3 years ago

Thank you so much!! Please find the outcome of the command that was asked to try: -

asadsayed@Asads-MacBook-Air whatsapp_converter % python whatsapp_converter.py _chat.txt chat.xlsx File "whatsapp_converter.py", line 224 print(f'{BCOLORS["WARNING"]}NOTE: The writing of the ODS file takes some time. Your terminal did not crash. Please wait ...{BCOLORS["ENDC"]}') ^ SyntaxError: invalid syntax

Hope this helps, thank you so much!!

sandsturm commented 3 years ago

I hope that I corrected the bug in version https://github.com/sandsturm/whatsapp-converter/releases/tag/v0.5.1. Please pull this to your local repository and give it a try.

Asad98 commented 3 years ago

Hello, thank you so much for correcting the bug, gave it a shot and faced the following result: -

asadsayed@Asads-MacBook-Air whatsapp_converter % python whatsapp_converter.py _chat.txt chat.xlsx File "whatsapp_converter.py", line 192 print(f'\n{BCOLORS["FAIL"]}Error: Excel 2003 only supports a maximum of 65535 lines. Whatsapp-converter found more than 65535 lines for input which might lead to an error.{BCOLORS["ENDC"]}\n') ^ SyntaxError: invalid syntax

Please advise if I am doing something incorrectly, the last time it said the error was on line 224, this time its on line 192. Also, let me know if program will work on a windows, if yes, I will run it there and send the result to my mac.

Really appreciate your help ! Thank you !

sandsturm commented 3 years ago

Okay, getting clearer. Can you please check your python version? This only runs on python3. python --version

If you have python3 installed you can give it a try by executing: python3 whatsapp_converter.py _chat.txt chat.xlsx

Asad98 commented 3 years ago

Hello, tried running the above, but the following new error pops up:-

asadsayed@Asads-MacBook-Air whatsapp_converter % python3 whatsapp_converter.py _chat.txt chat.xlsx Traceback (most recent call last): File "whatsapp_converter.py", line 19, in from whatsapp_converter import colors File "/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/whatsapp_converter.py", line 19, in from whatsapp_converter import colors ImportError: cannot import name 'colors' from partially initialized module 'whatsapp_converter' (most likely due to a circular import) (/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/whatsapp_converter.py)

Thank you for your time and efforts

sandsturm commented 3 years ago

Do this, go one directory up and execute python with the -m option: cd /Users/asadsayed/Downloads/whatsapp-converter-0.5.1/ python3 -m whatsapp_converter _chat.txt chat.xlsx

Asad98 commented 3 years ago

Hello, thanks once again, The following error pops up

asadsayed@Asads-MacBook-Air whatsapp-converter-0.5.1 % python3 -m whatsapp_converter _chat.txt chat.xlsx Reading import file Converting data now 0%| 0%| | 0/2102 [00:00<?, ?it/s] Traceback (most recent call last): File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/main.py", line 63, in main() File "/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/main.py", line 60, in main whatsapp_converter.convert(args) File "/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/whatsapp_converter.py", line 205, in convert buffer = parse(line, local_args) File "/Users/asadsayed/Downloads/whatsapp-converter-0.5.1/whatsapp_converter/whatsapp_converter.py", line 83, in parse date = datetime.datetime.strptime(match.group(1), "%m/%d/%Y").date() File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 568, in _strptime_datetime tt, fraction, gmtoff_fraction = _strptime(data_string, format) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/_strptime.py", line 349, in _strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '13/05/2020' does not match format '%m/%d/%Y'

Thank you!

sandsturm commented 3 years ago

Very good, at least it runs! Can you please attach an anonymzed chat export? I just need 5 lines, the date and time format is important, not the names or content. It is almost impossible to cover all possible combinations of the date and time.

Asad98 commented 3 years ago

Sure, thank you so much for your efforts!!

The format is as below : -

[13/05/2020, 2:11:22 am] Name: Message [13/05/2020, 2:12:22 am] Name: Message [13/05/2020, 2:13:22 am] Name: Message

Please note that some messages contain new lines, will this be factored into one cell? Thank you so much for your efforts, hope this helps someone in the future who is in my shoes at the moment!

sandsturm commented 3 years ago

Thank you very much. The script definetly did not support this format. I added it now, v0.5.3. Have fun!

By default, carriage return is merged into the same line in the export. But you can provide the -n or --newline argument to create a new line in the export for every carriage return. Please take a look at the documentation for further details.

Let me know if it finally worked 😁

Asad98 commented 3 years ago

It worked!! Thank you so much, I have only one issue though, it's a minor one. After the conversion, the excel file contained certain messages clubbed together, but this is only the case for attachments, the following is the message if an attachment is sent: -

" Message [18/06/2020, 11:48:58 am] Name: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg> ‎[18/06/2020, 11:48:59 am] Name: ‎<attached: 00000204-PHOTO-2020-06-18-11-48-58.jpg> ‎[18/06/2020, 11:48:59 am] Name: ‎<attached: 00000205-PHOTO-2020-06-18-11-48-59.jpg>"

The above is in the message cell corresponding to the sender along with the date and time, the previous message and the following attachments are put into one message cell until another message is sent through by the sender instead of an attachment. What is happening according to me is that the "<" is not taken into account as a message or not recognized into the program.

I really appreciate your efforts in iterating the code to match my use case. Also, I know this will help others in the future who are exporting WhatsApp messages from iOS and need them to be converted into excel. Having said that, I will also add and say that having gone this far is already amazing, if the above is fixed it would be an added bonus.

Thank you so much!

sandsturm commented 3 years ago

I am glad everything worked as expected. Diagnosing bugs remotely is really hard. 😁 That is exactly my intention. Add more formats so that it works better and better. I am always amazed at Whatsapp how many formats there are beyond the date and time formats. Sometimes with, sometimes without square brackets. Sometimes with seconds, sometimes without. Your help has definitely paid off.

Just to better understand it. The message looks like this?

[18/06/2020, 11:48:58 am] Name: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg> 
‎[18/06/2020, 11:48:59 am] Name: ‎<attached: 00000204-PHOTO-2020-06-18-11-48-58.jpg> ‎
[18/06/2020, 11:48:59 am] Name: ‎<attached: 00000205-PHOTO-2020-06-18-11-48-59.jpg>
Asad98 commented 3 years ago

Glad to be of some help, the major chunk of contribution comes from individuals like you, that's what I really appreciate.... As for the message, the message is not in a new line, it is separated by a space, also another thing to note is that preceding all of this is the last message by the sender. Let's consider a case, say me and you are chatting on WhatsApp, and I greet you with a message and an image of myself, below is the conversation [18/06/2020, 11:48:58 am] Asad: Hello! How are you, I am attaching sending my image in another message [18/06/2020, 11:49:58 am] Asad: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg>

After conversion, the following output is generated (please note that the below is in one row): - [18/06/2020, 11:48:58 am] (In the date and time columns) Asad(in the sender column): Hello! How are you, I am attaching sending my image in another message [18/06/2020, 11:49:58 am] Asad: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg> (In the message column)

The desired output would be: -

First row - [18/06/2020, 11:48:58 am] (In the date and time columns) Asad(in the sender column): Hello! How are you, I am attaching sending my image in another message (In the message column) Second row - [18/06/2020, 11:49:58 am] (In the date and time columns) Asad(in the sender column): <attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg> (In the message column)

Hope this is much better than my last explanation 😅 Thank you so much for your help!

sandsturm commented 3 years ago

Thank you very much for your explanation. I added the following lines to my test export:

[18/06/2020, 11:48:58 am] Asad: Hello! How are you, I am attaching sending my image in another message
[18/06/2020, 11:49:58 am] Asad: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg>
[18/06/2020, 11:50:00 am] Asad: ‎<attached: 00000203-PHOTO-2020-06-18-11-48-59.jpg>

It generates the desired format already without changing the current code. 🤔 Here is the csv export of the input from above:

Date and Time|Date|Time|Name|Message
2020-06-18 11:48|2020-06-18|11:48|Asad|Hello! How are you, I am attaching sending my image in another message
2020-06-18 11:49|2020-06-18|11:49|Asad|‎<attached: 00000203-PHOTO-2020-06-18-11-48-58.jpg>
2020-06-18 11:49|2020-06-18|11:49|Asad|‎<attached: 00000203-PHOTO-2020-06-18-11-48-59.jpg>
Asad98 commented 3 years ago

Hello, The code works fine, maybe there was something wrong with the txt file, when I created a fresh txt file pasted the contents of the generated txt file into the fresh one, it works perfectly. Well, anyways very happy that this finally worked out, thank you sooooo much for your help and quick fixes!!!

Best regards, Asad

sandsturm commented 3 years ago

Hi Asad,

Thank you very much. That sounds like a CR/LF issue.I'm glad it finally worked out and we both kept working on it. Do not hesitate to open new topics ;-)

Best regards, Martin