Closed KleanOcean closed 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")
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
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
No problem, I will try to see how to implement it too~
i think i did it, it's not perfect, but it's good enough for now
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 ")
though it cant read emoji,which will occur error, but overall it works well!
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
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
Can this code read the message from the others and give response?