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 🚀
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.
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.
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📄
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 🎁