Python Forum
Sending Whatsapp Message in the text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending Whatsapp Message in the text file
#1
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
Reply
#2
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)
Reply
#3
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)
Reply
#4
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:
Reply
#5
(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>
Reply
#6
Windows is messing up choosing wrong encoding.
Do this:
with open("footer.txt", encoding='utf-8') as f:
Reply
#7
(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.
Reply
#8
(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)
Reply
#9
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.

โ–โœจโœฆ โ”€โ”€๐ŸŒนโ”€โ”€ โœฆโœจโ–
โ”ผโ”ผโ”€โ”€โ”€โ”€โ”€โ”ผ
๐Ÿ’—๐Ÿ‘ง๐Ÿ’—โž•๐Ÿ’™
__๐Ÿ’ƒ
snippsat likes this post
Reply
#10
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 ๐Ÿ‘ป
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 3,024 Jan-21-2024, 01:12 PM
Last Post: owalahtole
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,071 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,580 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,843 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Trying to parse and work with the WhatsApp export of chats cubangt 6 2,606 Dec-16-2021, 08:20 PM
Last Post: cubangt
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,257 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Winning/Losing Message Error in Text based Game kdr87 2 2,928 Dec-14-2020, 12:25 AM
Last Post: bowlofred
  how to automate sending bulk emails from an excel file or a calc-file apollo 0 2,709 Dec-10-2020, 08:43 PM
Last Post: apollo
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,330 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  saving data from text file to CSV file in python having delimiter as space K11 1 2,356 Sep-11-2020, 06:28 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020