5 Python Scripts to Automate Your Life 🐍
Stop doing repetitive tasks manually. Let Python do the work for you.
We all have boring tasks we do every day on our computers. Renaming files, organizing downloads, sending emails, or checking stock prices. What if I told you that you can write a script once and never do these tasks manually again?
Here are 5 powerful Python scripts that are easy to write and incredibly useful.
1. The "Downloads Organizer" 📂
Is your Downloads folder a mess? This script automatically moves files into folders based on their extension (Images, PDFs, Videos, etc.).
import os
import shutil
# Define the directory to organize
source_dir = "C:/Users/YourName/Downloads"
# Define where to move files
folders = {
"Images": [".jpg", ".png", ".jpeg", ".gif"],
"Documents": [".pdf", ".docx", ".txt", ".xlsx"],
"Videos": [".mp4", ".mkv", ".mov"],
"Software": [".exe", ".msi", ".zip", ".rar"]
}
for filename in os.listdir(source_dir):
file_ext = os.path.splitext(filename)[1].lower()
for folder, extensions in folders.items():
if file_ext in extensions:
folder_path = os.path.join(source_dir, folder)
if not os.path.exists(folder_path):
os.makedirs(folder_path)
shutil.move(os.path.join(source_dir, filename), os.path.join(folder_path, filename))
print(f"Moved {filename} to {folder}")
2. Send WhatsApp Messages Automatically 📱
Forget to wish someone a happy birthday? Use the `pywhatkit` library to schedule messages.
First, install the library: pip install pywhatkit
import pywhatkit
# Syntax: phone_number, message, hour (24h), minute
pywhatkit.sendwhatmsg("+919876543210", "Happy Birthday! 🎂", 12, 00)
This will open WhatsApp Web in your browser and send the message at exactly 12:00 PM.
3. Bulk File Renamer 🏷️
Imagine you have 100 photos named "IMG_1023.jpg", "IMG_1024.jpg"... and you want them to be "Trip_Goa_1.jpg", "Trip_Goa_2.jpg". Doing this manually is torture.
import os
path = "C:/Photos/GoaTrip/"
files = os.listdir(path)
for index, filename in enumerate(files):
dst = f"Goa_Trip_{index + 1}.jpg"
src = f"{path}/{filename}"
dst = f"{path}/{dst}"
os.rename(src, dst)
print("All files renamed successfully!")
4. YouTube Video Downloader 📺
Want to save a tutorial for offline viewing? Python makes it super easy with `pytube`.
Install: pip install pytube
from pytube import YouTube
link = input("Enter YouTube Video URL: ")
yt = YouTube(link)
print(f"Downloading: {yt.title}")
stream = yt.streams.get_highest_resolution()
stream.download()
print("Download Completed!")
5. Price Tracker for Amazon 🛒
Don't overpay. This script checks the price of a product and emails you if it drops below your budget.
(Note: This requires `requests` and `bs4` for web scraping).
import requests
from bs4 import BeautifulSoup
url = "AMAZON_PRODUCT_URL"
headers = {"User-Agent": "Mozilla/5.0..."} # Add your user agent
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(id="productTitle").get_text().strip()
price = float(soup.find(class_="a-price-whole").get_text().replace(',', '').replace('.', ''))
if price < 50000:
print(f"Price Drop Alert! {title} is now {price}")
# Add email sending code here
Conclusion
Python is a superpower. Start with these simple scripts, and soon you'll be automating complex workflows. Happy Coding!