nmoya / whatsapp-parser

Parser to the What's App log file.
MIT License
47 stars 23 forks source link

Error in whatsapp.py #25

Closed darryl34 closed 5 years ago

darryl34 commented 5 years ago

Hi, I came across this error when trying to run the program. I'm fairly new to Python so I only understand some parts of your code.

File "C:\Users\Darryl\Downloads\whatsapp-parser-master\wp_parser\parsers\whatsapp.py", line 19, in parse
    msg_date, sep, msg = l.partition(": ")
TypeError: a bytes-like object is required, not 'str'

Your help will be much appreciated :)

manu-chroma commented 5 years ago

can you try using python 2.7? this project is not tested on python 3.

darryl34 commented 5 years ago

Okay. So I tried with Python 2.7. But I get this error. Is there a problem with my text file?

C:\Users\Darryl\Downloads\whatsapp-parser-master\whatsapp-parser-master>py -2  wp_parser/wp_chat.py -f chat.txt -n "Darryl" -r sleepy yes

Traceback (most recent call last):
  File "wp_parser/wp_chat.py", line 239, in <module>
    main()
  File "wp_parser/wp_chat.py", line 234, in main
    c.all_features(pattern_list=args['regexes'])
  File "wp_parser/wp_chat.py", line 110, in all_features
    self.features.compute_response_time_and_burst(self.messages, self.root, self.senders, initiation_thrs, burst_thrs, response_thrs)
  File "C:\Users\ASUS\Downloads\whatsapp-parser-master\whatsapp-parser-master\wp_parser\ChatFeatures.py", line 27, in compute_response_time_and_burst
    t0 = list_of_messages[0].datetime_obj
IndexError: list index out of range
nmoya commented 5 years ago

@darryl34 Yes, it looks like there is a problem in your chat history file.

darryl34 commented 5 years ago

Ahh I see. Okay. So I went and compared the test chat history file with my own file. Apparently, they added square brackets around the timestamp and changed the format from DD/MM/YY to DD/MM/YYYY. Did these changes affect the code?

My file: sample_chat.txt The test file: 22_OW_MT.txt

nmoya commented 5 years ago

@darryl34 I don't remember the code anymore 🙈 You can try with a single line file, like this:

02/02/2019, 9:14:54 AM Darryl: hi hi!

If it works, that's the problem!

darryl34 commented 5 years ago

Nope, still the same problem. Oh well. Thanks for your help!

nmoya commented 5 years ago

@darryl34 Huh, it's weird that it didn't work. if it works with the sample chat, it is definitely formatting on the input. Try brute forcing a little bit with some very simple examples.

manu-chroma commented 5 years ago

@darryl34 can you post a few sample messages here? I'll try to help out in free time.

darryl34 commented 5 years ago

@manu-chroma @nmoya sorry i forgot to add a colon after AM. the code works.

Is there a limit to the average response time. Eg. we dont speak for a couple of days. Will that count?

And, what exactly are contact bursts and initiations?

nmoya commented 5 years ago

Hey @darryl34,

Yes, there is a response time threshold. Default is 3 hours. This means that if the messages where being exchanged within this threshold, it's all being used for the response time. If it takes longer than the threshold, a new average is started.

Contact bursts are how many times a person burst messages at the other.

Hi
Are you there?
How are you?
Can you read this?

This is a burst.

Initiation is a counter of how many times a person initiated a conversation. There is also a default threshold to increment the initiations, which is 8 hours. So, messages within 8 hours apart is the same "initiation", more than that it's a "new conversation" in which the first sender-initiated it.

darryl34 commented 5 years ago

Ah why didn't I think of that earlier

Many thanks!