Welcome to the Python Projects for Beginners Series ๐๐ปโโ๏ธ
I'm Sai Ashish and today, I'm going to show you how to spam your friends by building a message bomber using just 6 lines of code๐
How psyched are you for this build? Let's get started ๐
What are we going to learn today?
1. The PyAutoGUI module
2. The Time module
3. Basics of Python: Iterative Statement
4. Implementation of Message Bomber Using Python with detailed explanation
P.S. Use this project wisely for fun purposes only. Don't go on spamming people and get blocked ๐
For this build, we are going to use the PyAutoGUI module of Python.
1. What is PyAutoGUI?
PyAutoGUI is a python module that lets you control your mouse and keyboard using a program.
To install PyAutoGUI in your system, open your terminal and run:
pip install pyautogui
PyAutoGUI has several features including:
- Moving the mouse and clicking or typing in the windows of other applications.
- Sending keystrokes to applications (for example, to fill out forms).
- Take screenshots, and given an image (for example, of a button or checkbox), find it on the screen.
- Locate an applicationโs window, and move, resize, maximize, minimize, or close it (Windows-only, currently)
- Display message boxes for user interaction while your GUI automation script runs.
Source: Official documentation of PyAutoGUI.
PyAutoGUI also lets you automate your everyday tasks and can play games, login into emails, and more.
2. What is the Time Module?
The time module provides various time-related functions. We use it to retrieve the system time and display it on the screen. You can access the official documentation form here๐
3. Time to Code!
You can access the exclusive theory for this build here๐ฃ
The first step is to import the PyAutoGUI and the Time module.
# Importing the required libraries
import pyautogui, time
Next, we need to set the program to sleep for 10 seconds. you'll get to know the reason at the end of the implementation.
# Delay to switch windows
time.sleep(10)
I plan to spam my friend with the script of the Green Lantern movie ๐ฎ Sorry, Ryan ๐
I already have downloaded the script of the movie. All I have to do is to load it into my environment.
Make sure to provide the full path of the file with an extension, if the file isn't located at the same location as the program. Otherwise, the name of the file with the extension is enough.
# Load the file contents in read mode
file = open("Green-Lantern-Movie-Script.txt", 'r')
You've loaded the word bullets. Your program gun is on point. All that's left to do is fire it ๐ฅ
# loop to spam
for word in file:
# Fetch and type each word from the file
pyautogui.write(word)
# Press enter to send the message
pyautogui.press('enter')
Here, we set a loop to iterate over each word in the file. We use write() function to type the keys and then use the press() function to click enter and send the message. Therefore, our message bomber takes each word from the file and spams right into where we want to.
Your program is ready. Let me show you how it's done ๐
Step 1: Open your Python environment ๐
Step 2: Open the app through which you want to spam ๐ฑ
Step 3: Run the message bomber program ๐๐ปโโ๏ธ
Step 4: Quickly switch the window from the python environment to the application and point the cursor on the user's chat area. We chose the delay of 10 seconds to perform this action in the meantime โณ
Step 5: Step back, grab some popcorn, and watch your bot unleash the power ๐ฟ
The final source code looks like this:
If you do not want to use a file, you can just eliminate the file statement and use
pyautogui.write("Random Annoying Spam Words")
instead of pyautogui.write(word) while keeping a count loop.
We did it ๐ฅณ We have made our own Message Bomber using Python in just 6 lines of code! How amazing is that? As a gift for staying till now, you get access to my Python For Beginners Series Repository ๐ This repository contains all the source code you'd need to get started as a Python Developer ๐.
You can also download the source code to this project here. Do hit the twinkle star, if this article provided value to you ๐ฅ
And while you're at it, consider giving this blog the maximum love you can and I promise to give you such value bombs every week ๐ฃ Until then, take care ๐๐ปโโ๏ธ
Bonus Insights by The Insightful Coder :
Interested in Building Your Own Artificial Intelligence Projects using Python?: Check out the Python AI Series๐ง
Wanna Discover Some Valuable Tech-Hacks ๐ ?: Check out the Tech-Hacks for Everybody Series๐
Wanna Interact With Me ๐๐ปโโ๏ธ? Connect With Me on Your Favourite Platform Here ๐ค๐ป
Find and Download All My Project Source Codes at My Github Repository ๐
Top comments (0)