### Install PyWhatKit Library Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Command to install the PyWhatKit package via pip. ```bash pip install pywhatkit ``` -------------------------------- ### Install PyWhatKit via Pip Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Commands to install the PyWhatKit library using Python's package manager. ```bash python3 -m pip install pywhatkit ``` ```bash pip3 install pywhatkit ``` -------------------------------- ### Start Remote Control Server Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Initializes the remote control server to allow PC control via a mobile device on the same network. ```python import pywhatkit pywhatkit.start_server() ``` -------------------------------- ### Automate WhatsApp and Media Tasks Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Examples of using PyWhatKit to send WhatsApp messages, images, play YouTube videos, and convert images to ASCII art. ```python import pywhatkit # Send a WhatsApp Message to a Contact at 1:30 PM pywhatkit.sendwhatmsg("+910123456789", "Hi", 13, 30) # Send an Image to a Group with the Caption as Hello pywhatkit.sendwhats_image("AB123CDEFGHijklmn", "Images/Hello.png", "Hello") # Send a WhatsApp Message to a Group instantly pywhatkit.sendwhatmsg_to_group_instantly("AB123CDEFGHijklmn", "Hey All!") # Play a Video on YouTube pywhatkit.playonyt("PyWhatKit") # Converting image to ASCII Art ascii_art = pywhatkit.image_to_ascii_art("image path") print(ascii_art) ``` -------------------------------- ### Remote Control Server Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Function to start a remote control server for PC control from a mobile device. ```APIDOC ## start_server - Start Remote Control Server ### Description Starts a web server that allows remote control of the PC from a mobile phone on the same network. This is a Windows-only feature. ### Method ```python start_server(port: int = 8000, print_msg: bool = False) ``` ### Endpoint N/A (Local function) ### Parameters - **port** (int) - Optional - The port number to start the server on. Defaults to 8000. - **print_msg** (bool) - Optional - If True, prints connection messages. Defaults to False. ### Request Example ```python import pywhatkit # Start on default port 8000 pywhatkit.start_server() # Start on a custom port with messages printed pywhatkit.start_server(port=5000, print_msg=True) ``` ### Usage Instructions 1. Find your PC's IP address using `ipconfig` in the command prompt. 2. On your phone's browser, navigate to: `http://YOUR_IP:PORT` (replace YOUR_IP and PORT with your PC's IP and the server port). 3. Use the touch interface to control the mouse, type text, and scroll. ``` -------------------------------- ### GET /info Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Retrieves information about a specific topic from Wikipedia. ```APIDOC ## GET /info ### Description Fetches details about a given topic using the Wikipedia API. ### Method GET ### Parameters #### Query Parameters - **topic** (str) - Required - The subject to search on Wikipedia. - **lines** (int) - Optional - Number of lines to return (default: 3). - **return_value** (bool) - Optional - Whether to return the string or print it (default: False). ### Request Example pywhatkit.info("Python Language", 10) ### Response #### Success Response (200) - **data** (str) - The fetched Wikipedia summary. ``` -------------------------------- ### GET /search Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Performs a Google search for a specific topic. ```APIDOC ## GET /search ### Description Opens a new browser tab with Google search results for the provided topic. ### Method GET ### Parameters #### Query Parameters - **topic** (str) - Required - The search term. ### Request Example pywhatkit.search("Python") ``` -------------------------------- ### Get Wikipedia Information with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Retrieves and displays information about a specified topic from Wikipedia. Users can control the number of lines returned and choose to get the data as a string instead of printing it directly. ```python import pywhatkit # Get 3 lines of information (default) pywhatkit.info("Python programming language") # Get 5 lines of information pywhatkit.info("Machine Learning", lines=5) # Get information and return as string data = pywhatkit.info( topic="Artificial Intelligence", lines=4, return_value=True ) print(f"Retrieved: {data}") ``` -------------------------------- ### YouTube and System Automation Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Methods for playing YouTube videos and initiating remote server control. ```APIDOC ## GET /playonyt ### Description Searches and plays a video on YouTube. ### Method GET ### Parameters #### Query Parameters - **topic** (string) - Required - The search query for the YouTube video. ## POST /start_server ### Description Starts a local server to enable remote control of the PC via a web browser. ### Method POST ### Parameters None ``` -------------------------------- ### Clone PyWhatKit Repository Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Command to clone the source code from GitHub. ```bash git clone https://github.com/Ankit404butfound/PyWhatKit.git ``` -------------------------------- ### Open WhatsApp Web Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Utility function to initialize a WhatsApp Web session in the default browser. ```python import pywhatkit # Open WhatsApp Web success = pywhatkit.open_web() if success: print("WhatsApp Web opened successfully") else: print("Failed to open WhatsApp Web") ``` -------------------------------- ### Handle PyWhatKit Exceptions Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Demonstrates how to catch and handle specific custom exceptions raised by PyWhatKit during automation tasks like messaging or email sending. ```python import pywhatkit from pywhatkit.core.exceptions import ( CountryCodeException, CallTimeException, InternetException, InvalidPhoneNumber, UnsupportedEmailProvider, UnableToAccessApi ) try: pywhatkit.sendwhatmsg_instantly("1234567890", "Hello") except CountryCodeException: print("Please include country code (e.g., +1)") try: pywhatkit.sendwhatmsg("+1234567890", "Hi", 12, 30, wait_time=60) except CallTimeException: print("Scheduled time must be greater than wait time") ``` -------------------------------- ### Perform Google Search with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Opens the default web browser to perform a Google search for a given topic. This is a straightforward way to automate web searches. ```python import pywhatkit # Search for a topic on Google pywhatkit.search("PyWhatKit documentation") pywhatkit.search("Python automation libraries") ``` -------------------------------- ### Schedule System Shutdown with PyWhatKit Source: https://github.com/ankit404butfound/pywhatkit/wiki/Shutdown-and-CancelShutdown Schedules the host machine to shut down after a specified duration. Note that Windows requires time in seconds, while MacOS and Linux require time in minutes. ```python import pywhatkit # Shutdown after 5 units (Seconds for Windows, Minutes for Linux/MacOS) pywhatkit.shutdown(5) ``` -------------------------------- ### Capture System Screenshot Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Captures a screenshot on Windows or MacOS and saves it as a PNG file. Includes parameters for custom filenames and a delay before capture. ```python import pywhatkit pywhatkit.take_screenshot("myscreenshot", delay=2) ``` -------------------------------- ### POST /playonyt Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Plays a YouTube video based on a search topic. ```APIDOC ## POST /playonyt ### Description Searches and plays the most relevant YouTube video for a given topic. ### Method POST ### Parameters #### Request Body - **topic** (str) - Required - The search query for YouTube. - **use_api** (bool) - Optional - Use PyWhatKit API to fetch URL (default: False). - **open_video** (bool) - Optional - Automatically open the video in the browser (default: True). ### Request Example pywhatkit.playonyt("Python", True) ### Response #### Success Response (200) - **url** (str) - The URL of the video found. ``` -------------------------------- ### POST /take_screenshot Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Captures a screenshot of the current screen. ```APIDOC ## POST /take_screenshot ### Description Takes a screenshot and saves it as a PNG file. Supported on MacOS and Windows. ### Method POST ### Parameters #### Request Body - **file_name** (str) - Optional - The name of the output file (default: "pywhatkit_screenshot"). - **delay** (int) - Optional - Delay in seconds before capture (default: 2). ### Request Example pywhatkit.take_screenshot("myscreenshot") ``` -------------------------------- ### Play YouTube Video on PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Plays the first search result for a given topic on YouTube. It can optionally return the video URL without opening the browser or use an API for searching. ```python import pywhatkit # Play a video by search query url = pywhatkit.playonyt("Python tutorial for beginners") print(f"Playing video: {url}") # Get URL without opening browser url = pywhatkit.playonyt( topic="Machine Learning basics", open_video=False # Don't open in browser ) print(f"Video URL: {url}") # Use the API for search (alternative method) url = pywhatkit.playonyt( topic="Django REST framework", use_api=True ) ``` -------------------------------- ### Convert Image to ASCII Art with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Converts an image file into ASCII art text. The output is saved to a text file and also returned as a string. The default output filename is 'pywhatkit_asciiart.txt'. ```python import pywhatkit # Convert image to ASCII art ascii_art = pywhatkit.image_to_ascii_art( img_path="path/to/image.png", output_file="my_ascii_art" # Saves to my_ascii_art.txt ) print(ascii_art) # Default output filename is "pywhatkit_asciiart.txt" ascii_art = pywhatkit.image_to_ascii_art("profile_photo.jpg") ``` -------------------------------- ### Take Screenshot with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Captures a screenshot of the current screen. This functionality is available on Windows and macOS. Options include specifying a filename, a delay before capture, and whether to display the screenshot immediately. ```python import pywhatkit # Take a screenshot with default settings pywhatkit.take_screenshot( file_name="my_screenshot", # Saves as my_screenshot.png delay=2, # Wait 2 seconds before capture show=True # Show the screenshot after capture ) # Take a quick screenshot without preview pywhatkit.take_screenshot( file_name="quick_capture", delay=0, show=False ) ``` -------------------------------- ### Open WhatsApp Web Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Opens the WhatsApp Web interface in the default browser. Returns a boolean indicating if the operation was successful. ```python import pywhatkit pywhatkit.open_web() ``` -------------------------------- ### Convert Image to ASCII Art using PyWhatKit Source: https://github.com/ankit404butfound/pywhatkit/wiki/ASCII-Art This function converts an image file to an ASCII art text file. It accepts the image path as a required argument and an optional output filename, defaulting to 'pywhatkit_asciiart.txt'. ```python import pywhatkit # Convert image in the same directory pywhatkit.image_to_ascii_art("Example.png") # Convert image using an absolute path pywhatkit.image_to_ascii_art("C:\\Example\\Example.png") # Convert image with a custom output filename pywhatkit.image_to_ascii_art("Example.png", "my_ascii_art") ``` -------------------------------- ### Exception Handling Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Custom exceptions provided by PyWhatKit for robust error handling. ```APIDOC ## Exception Handling PyWhatKit defines several custom exceptions for error handling. It is recommended to catch these exceptions to gracefully handle potential issues. ### Available Exceptions - **CountryCodeException**: Raised when a phone number is missing the country code. - **CallTimeException**: Raised when the scheduled call time is invalid (e.g., before the current time or too close to the wait time). - **InternetException**: Raised when there is no internet connection. - **InvalidPhoneNumber**: Raised when a phone number is not in a valid format. - **UnsupportedEmailProvider**: Raised when an unsupported email provider is used for sending emails. - **UnableToAccessApi**: Raised when there is an issue accessing an external API. ### Example Usage ```python import pywhatkit from pywhatkit.core.exceptions import ( CountryCodeException, CallTimeException, InternetException, InvalidPhoneNumber, UnsupportedEmailProvider, UnableToAccessApi ) try: # Example: Sending a message instantly with an invalid phone number pywhatkit.sendwhatmsg_instantly("+1abc", "Test message") except InvalidPhoneNumber: print("Error: The provided phone number format is invalid.") try: # Example: Scheduling a message with an invalid time pywhatkit.sendwhatmsg("+11234567890", "Hello", 12, 30, wait_time=60) except CallTimeException: print("Error: The scheduled time must be greater than the current time and wait time.") try: # Example: Sending an email with an unsupported provider pywhatkit.send_mail("user@unsupported.com", "password", "Subject", "Body", "recipient@email.com") except UnsupportedEmailProvider: print("Error: Email provider not supported. Please use Gmail, Yahoo, Outlook, or AOL.") try: # Example: Function that might require API access pywhatkit.text_to_handwriting("Some text") except UnableToAccessApi: print("Error: Could not connect to the required API. Check your internet connection.") ``` ``` -------------------------------- ### Convert Text to Handwriting Image with PyWhatKit Source: https://github.com/ankit404butfound/pywhatkit/wiki/Text-to-Handwriting This function converts a string into an image file that mimics handwriting. Users can customize the output filename and the RGB color of the text. ```python import pywhatkit # Basic usage pywhatkit.text_to_handwriting("Hello") # Usage with custom filename pywhatkit.text_to_handwriting("Hello", "filename.png") # Usage with custom filename and RGB color pywhatkit.text_to_handwriting("Hello", "filename.png", (0, 0, 138)) ``` -------------------------------- ### Perform Google Search Source: https://github.com/ankit404butfound/pywhatkit/wiki/Miscellaneous-Functions Opens a new browser tab and performs a Google search for the specified topic. ```python import pywhatkit pywhatkit.search("Python") ``` -------------------------------- ### Send Media and Documents via WhatsApp Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Functions to send images, videos, and documents to contacts or groups. ```python import pywhatkit # Send image to a contact with caption pywhatkit.sendwhats_image( receiver="+1234567890", img_path="path/to/image.png", time_hour=15, time_min=45, caption="Check out this photo!", wait_time=15, tab_close=True, close_time=3 ) # Send video instantly pywhatkit.sendimg_or_video_immediately( phone_no="+1234567890", path="path/to/video.mp4", wait_time=15, tab_close=True, close_time=3 ) # Send a PDF document pywhatkit.sendwhatdoc_immediately( phone_no="+1234567890", path="path/to/document.pdf", wait_time=15, tab_close=True, close_time=3 ) ``` -------------------------------- ### Manage PyWhatKit Message Logs Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Functions to display the history of sent messages and configure the directory where the log file is stored. ```python import pywhatkit # Show all logged messages pywhatkit.show_history() # Set custom log directory pywhatkit.set_log_path("C:\\Users\\Username\\Documents\\Logs") ``` -------------------------------- ### WhatsApp Automation Methods Source: https://github.com/ankit404butfound/pywhatkit/blob/master/README.md Methods for sending messages and images to WhatsApp contacts and groups. ```APIDOC ## POST /sendwhatmsg ### Description Sends a WhatsApp message to a specific contact at a scheduled time. ### Method POST ### Parameters #### Request Body - **phone_no** (string) - Required - The recipient's phone number with country code. - **message** (string) - Required - The content of the message. - **time_hour** (int) - Required - The hour in 24-hour format. - **time_min** (int) - Required - The minute of the hour. ### Request Example { "phone_no": "+910123456789", "message": "Hi", "time_hour": 13, "time_min": 30 } ## POST /sendwhats_image ### Description Sends an image to a WhatsApp contact or group with an optional caption. ### Method POST ### Parameters #### Request Body - **receiver** (string) - Required - Phone number or Group ID. - **img_path** (string) - Required - Local path to the image file. - **caption** (string) - Optional - Caption text for the image. ### Request Example { "receiver": "+910123456789", "img_path": "Images/Hello.png", "caption": "Hello" } ``` -------------------------------- ### Image to ASCII Art Conversion Source: https://github.com/ankit404butfound/pywhatkit/wiki/ASCII-Art Converts an image file into ASCII art and saves it to a text file. Supports relative and absolute paths for input images and allows customization of the output filename. ```APIDOC ## image_to_ascii_art ### Description Converts an image to ASCII art and saves it to a text file. The output file defaults to `pywhatkit_asciiart.txt` but can be customized. ### Method ```python image_to_ascii_art(img_path: str, output_file: str = "pywhatkit_asciiart") -> str ``` ### Parameters #### Path Parameters - **img_path** (str) - Required - The path to the input image file. Can be a relative or absolute path. - **output_file** (str) - Optional - The desired filename for the output ASCII art text file (without extension). Defaults to `pywhatkit_asciiart`. ### Request Example **Using default output file:** ```python import pywhatkit pywhatkit.image_to_ascii_art("Example.png") ``` **Using a specific output file:** ```python import pywhatkit pywhatkit.image_to_ascii_art("Example.png", "my_ascii_art") ``` **Using an absolute path for the image:** ```python import pywhatkit pywhatkit.image_to_ascii_art("C:\\Users\\User\\Pictures\\Example.png", "my_ascii_art") ``` ### Response #### Success Response (str) - Returns the path to the generated ASCII art file. ``` -------------------------------- ### Cancel Scheduled System Shutdown with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Cancels any system shutdown that has been previously scheduled using the `pywhatkit.shutdown()` function. ```python import pywhatkit # Cancel the scheduled shutdown pywhatkit.cancel_shutdown() ``` -------------------------------- ### Send Standard Email with PyWhatKit Source: https://github.com/ankit404butfound/pywhatkit/wiki/Sending-a-Mail Sends a plain text email using the send_mail function. It automatically detects the SMTP server based on the sender's email domain and requires an App Password for authentication. ```python import pywhatkit pywhatkit.send_mail("test@test.com", "password", "Test Mail", "This is a test email", "testrecv@test.com") ``` -------------------------------- ### Send Instant WhatsApp Messages Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Functions to send messages immediately without scheduling. Supports emoji syntax using colons. ```python import pywhatkit # Send a message immediately pywhatkit.sendwhatmsg_instantly( phone_no="+1234567890", message="Hello! Sending this message right now.", wait_time=15, tab_close=True, close_time=3 ) # Send with emoji support using colons pywhatkit.sendwhatmsg_instantly( phone_no="+1234567890", message="Great work! :thumbsup: Keep it up!" ) ``` -------------------------------- ### Send HTML Email with PyWhatKit Source: https://context7.com/ankit404butfound/pywhatkit/llms.txt Sends an email containing HTML content, allowing for rich formatting and links. Similar to sending plain text emails, it uses SMTP and supports various email providers. ```python import pywhatkit # Send an HTML email html_content = ""
Thank you for signing up for our newsletter.