A Python Module PyWhatKit for Automation

  • Post author:
  • Post comments:0 Comments
  • Reading time:54 mins read

PyWhatKit is a Python module that allows you to schedule tasks or notifications to be displayed at a specific time in the future. This is useful if you want to be reminded of something or if you want to automate a task to be performed at a specific time.

To use PyWhatKit, you will need to install it using

pip install pywhatkit.

Once it is installed, you can import it into your Python code using

import pywhatkit.

To schedule a task or notification, you can use the sendwhatmsg function. This function takes four arguments: the hour, the minute, the message, and the website to open (optional). For example, to schedule a notification for 10:30am that says “Time for a break!”, you can use the following code:


import pywhatkit

pywhatkit.sendwhatmsg(10, 30, "Time for a break!")

You can also schedule a task to open a website at a specific time. For example, to open web.whatsapp.com at 11:00am, you can use the following code:


import pywhatkit

pywhatkit.sendwhatmsg(11, 0, "Open website", "https://web.whatsapp.com/")

In addition to the sendwhatmsg function, PyWhatKit also provides several other functions for scheduling tasks and notifications. For example, you can use the playonyoutube function to play a specific YouTube video at a specific time, or the alarm function to set an alarm for a specific time.

Overall, PyWhatKit is a useful and convenient Python module for scheduling tasks and notifications in the future. It is easy to use and can be a great addition to any Python project that requires automated tasks or reminders.

Here is an example code that demonstrates how to use the PyWhatKit module to schedule a notification for 10:30am that says “Time for a meeting!”:


import pywhatkit

# Schedule the notification for 10:30am
pywhatkit.sendwhatmsg(10, 30, "Time for a meeting!")

print("Notification scheduled for 10:30am")

This code will schedule the notification to be displayed at 10:30am. You can change the hour and minute values to schedule the notification for a different time.

You can also add additional options to customize the notification. For example, you can use the speak argument to have the notification read aloud by your computer’s text-to-speech function. You can also use the interval argument to repeat the notification at regular intervals.

Here is an example code that demonstrates how to use these additional options:


import pywhatkit

# Schedule the notification for 10:30am and have it repeat every 30 minutes
pywhatkit.sendwhatmsg(10, 30, "Time for a meeting!", speak=True, interval=30)

print("Notification scheduled for 10:30am and will repeat every 30 minutes")

To send a message using the PyWhatKit module, you will need to use the sendwhatmsg function and specify the phone number and message as arguments.

Automate WhatsApp message sending using pywhatkit

Here is an example code that demonstrates how to send a message to the phone number +91xxxxxxxxxx with the message “Hello, how are you?” using PyWhatKit:

Note: You can give the mobile number according to the person number that you are willing to send a WhatsApp message


import pywhatkit

# Send the message at 10:00am
pywhatkit.sendwhatmsg(10, 0, "Hello, how are you?", "+91xxxxxxxxxx")

print("Message scheduled for delivery at 10:00am")

Keep in mind that PyWhatKit does not have the ability to send messages directly through WhatsApp. Instead, it uses your computer’s web browser to open a pre-filled message on the WhatsApp website. This means that you will need to have WhatsApp web open in your web browser for the message to be sent.

Now Let’s update our code and add some new features, such as collecting users input. Let’s move on it and add some features to our existing Python code


import pywhatkit

while True:

    print("please type the phone number with country code \n ")
    
    number = input("Enter the Reciever number to send message \n >>>")
    
    try:
        value = int(number)
        
        message = input("Enter the message you want to send \n >>>")
        
        time = input("Enter the time you want to send the message \n >>>")
        
        min = input("Enter in which min you want to send the message \n >>>")
        
        break;
        
    except ValueError:
    
        print("This is not a number. Please enter a valid number")
        
pywhatkit.sendwhatmsg(number,message,int(time),int(min))

Let’s play a youtube video with this module

You can use the command pywhatkit.playonyt() to open your default browser to YouTube and plays the video you specified in the feature. It plays a random video on that subject if you pass the topic name as a parameter. It opens the specific video when the URL is passed as a parameter.

Let’s move on to it. We can do it by a given command

You can use pywhatkit.playonyt(“Coding”) This will start playing the first video that comes up when you search for “Coding” on YouTube.


import pywhatkit

pywhatkit.playonyt("Coding")

After this let’s take a look at how can we perform a google search using this module

Google Search Using this module

You can also use this module to search in Google you can do it by the following command pywhatkit.search(“coding”)


import pywhatkit

pywhatkit.search("coding")

Hope this tutorial will help you How to use the Python module PyWhatKit for automation

Publisher
Latest posts by Publisher (see all)

Publisher

Publisher @ideasorblogs

Leave a Reply