Python Forum

Full Version: Sending Whatsapp Message in the text file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am sending whatsapp message through python. Below is the code.

import pywhatkit
pywhatkit.sendwhats_image("E9wnucCUpBpD1aizIUyLv6", "E:\\PythonFiles\\Music.jpg", "footer.txt", 10)
pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", "Test", 13, 3, 15, True, 5)
But i want to send a paragraph of message which is typed and saved in the same directory in text file.
How can i code to take message from the text file.

Thanks for the big help.

regards,
ebin
If pywhatkit don't take a file object you can do it like this.
import pywhatkit

with open("footer.txt") as f:
    pywhatkit.sendwhats_image("E9wnucCUpBpD1aizIUyLv6", "E:\\PythonFiles\\Music.jpg", f.read(), 10)
    pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", "Test", 13, 3, 15, True, 5)
But i get error like this

Error:
Traceback (most recent call last): File "C:\Users\sisya\PycharmProjects\Whatsapppython\main.py", line 9, in <module> with open("footer.txt") as f: FileNotFoundError: [Errno 2] No such file or directory: 'footer.txt'
(Jun-21-2022, 10:49 AM)snippsat Wrote: [ -> ]If pywhatkit don't take a file object you can do it like this.
import pywhatkit

with open("footer.txt") as f:
    pywhatkit.sendwhats_image("E9wnucCUpBpD1aizIUyLv6", "E:\\PythonFiles\\Music.jpg", f.read(), 10)
    pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", "Test", 13, 3, 15, True, 5)
You most have footer.txt in same folder as main.py.
Or give path to where you have footer.txt.
with open(r"C:\somefolder\footer.txt") as f:
(Jun-21-2022, 11:27 AM)snippsat Wrote: [ -> ]You most have footer.txt in same folder as main.py.
Or give path to where you have footer.txt.
with open(r"C:\somefolder\footer.txt") as f:

Below is the error i am receiving. I guess there should be string explained inside the bracket in f.read().

    pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", f.read(), 15, 2)
Error:
C:\Users\sisya\PycharmProjects\Whatsapppython\venv\Scripts\python.exe C:/Users/sisya/PycharmProjects/Whatsapppython/main.py Traceback (most recent call last): File "C:\Users\sisya\PycharmProjects\Whatsapppython\main.py", line 18, in <module> pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", f.read(), 15, 2) File "E:\Python310\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10: character maps to <undefined>
Windows is messing up choosing wrong encoding.
Do this:
with open("footer.txt", encoding='utf-8') as f:
(Jun-21-2022, 12:22 PM)snippsat Wrote: [ -> ]Windows is messing up choosing wrong encoding.
Do this:
with open("footer.txt", encoding='utf-8') as f:

Error:
IndentationError: expected an indented block after 'with' statement on line 17
the above error comes for indented block after with statement.
(Jun-21-2022, 12:44 PM)ebincharles869 Wrote: [ -> ]the above error comes for indented block after with statement.
Yes,Python need indentation ๐Ÿง
import pywhatkit

with open("footer.txt", encoding='utf-8') as f:
    pywhatkit.sendwhats_image("E9wnucCUpBpD1aizIUyLv6", "E:\\PythonFiles\\Music.jpg", f.read(), 10)
    pywhatkit.sendwhatmsg_to_group("E9wnucCUpBpD1aizIUyLv6", "Test", 13, 3, 15, True, 5)
Its working Perfectly. Thank you.

However it works only when there English texts. I need to insert some symbols like below and other languages texts. I hope the copy paste function works. Is that possible.

โ–โœจโœฆ โ”€โ”€๐ŸŒนโ”€โ”€ โœฆโœจโ–
โ”ผโ”ผโ”€โ”€โ”€โ”€โ”€โ”ผ
๐Ÿ’—๐Ÿ‘ง๐Ÿ’—โž•๐Ÿ’™
__๐Ÿ’ƒ
It depend on what pywhatkit accept,it works from Python side.
with open("test.txt", encoding='utf-8') as f:
    print(f.read())
Output:
Hello ๐Ÿ’—๐Ÿ‘ง๐Ÿ’—โž•๐Ÿ’™
Try different stuff and just one Emoji at time as test.
print(f'\N{grinning face}')
print(f'\N{eye}')
Output:
๐Ÿ˜€ ๐Ÿ‘
emoji 1.7.0
# pip install emoji
import emoji

print(emoji.emojize('Python is :thumbs_up:'))
print(emoji.emojize('Python is fun :ghost:'))
Output:
Python is ๐Ÿ‘ Python is fun ๐Ÿ‘ป