italoseara / whatsappy

A whatsapp api made with selenium in Python
MIT License
43 stars 8 forks source link

Read message from the others #10

Closed KleanOcean closed 2 years ago

KleanOcean commented 2 years ago

Can this code read the message from the others and give response?

italoseara commented 2 years ago
from whatsappy import Whatsapp

whatsapp = Whatsapp()

whatsapp.login()

chat = whatsapp.chat("Chat Name")
message = chat.last_message # Read the last message sent in chat

# to quote the message
message.reply("Hi")

# to simply send a message
chat.send("Hi")
KleanOcean commented 2 years ago

chat.last_message return a none which is <class 'NoneType'> is it about the web setting? the querySelector cant fetch the correct elements from the web. I used it in a whatsapp group, and there are text and pictures before the whatappy code started

italoseara commented 2 years ago

I'm sorry for that, I'll need some time to reprogram this, it's poorly done, I'll try to make it better by this weekend

KleanOcean commented 2 years ago

No problem, I will try to see how to implement it too~

italoseara commented 2 years ago

i think i did it, it's not perfect, but it's good enough for now

KleanOcean commented 2 years ago

Thanks!!! I am in Hong Kong, and the time_msg returned is non zero-padded, so it has error in the message.py

I added a '0' before the time-msg to make it zero-padded so the code runs well!

here is my fix/workaround message.py: self.text = parse_message(copyabletext.find(class="copyable-text").span)

        time_msg = re.compile(r"(\d+:\d+(\s)?(AM|PM)?)").findall(msg_metadata)[0][0]
        date_msg = re.compile(r"(\d+/\d+/\d+)").findall(msg_metadata)[0]
        self.author = re.compile(r"] (.*):").findall(msg_metadata)[0]
        # if not zero-padded
       >>>>> if(len(time_msg)==5):
       >>>>>     time_msg = "0" + time_msg
        self.time = (
            datetime.strptime(f"{date_msg} {time_msg}", "%m/%d/%Y %I:%M %p")
            if ("AM" in time_msg) or ("PM" in time_msg)
            else datetime.strptime(f"{date_msg} {time_msg}", "%d/%m/%Y %H:%M ")
KleanOcean commented 2 years ago

though it cant read emoji,which will occur error, but overall it works well!

italoseara commented 2 years ago

i'll try to find a way to parse every datetime format as soon as i get home, i never got this error before, thanks for reporting it

italoseara commented 2 years ago

btw, about emojis, some times it will think it is a sticker or a image because of the way that i coded it, i already thought about that, ill try to fix it ASAP