Here are some top Python automation scripts that can simplify everyday tasks:
1. Automate Web Scraping (Extract Data from Websites)
This script fetches the latest news headlines from a website.
import requests
from bs4 import BeautifulSoup
url = "https://news.ycombinator.com/"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
for idx, item in enumerate(soup.find_all("a", class_="storylink")[:5], start=1):
print(f"{idx}. {item.text}")
2. Automate Sending Emails
Sends an email automatically.
import smtplib
from email.message import EmailMessage
def send_email():
email = "your_email@gmail.com"
password = "your_password"
recipient = "recipient_email@gmail.com"
msg = EmailMessage()
msg["Subject"] = "Automated Email"
msg["From"] = email
msg["To"] = recipient
msg.set_content("Hello! This is an automated email.")
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(email, password)
server.send_message(msg)
send_email()
print("Email sent successfully!")
🔹 Tip: Use an App Password instead of your Gmail password.
3. Bulk File Renaming
Renames all files in a folder sequentially.
import os
folder_path = "/path/to/folder"
prefix = "file_"
for count, filename in enumerate(os.listdir(folder_path)):
old_path = os.path.join(folder_path, filename)
new_path = os.path.join(folder_path, f"{prefix}{count}.txt")
os.rename(old_path, new_path)
print("Files renamed successfully!")
4. Convert Text to Speech
Converts text into speech using pyttsx3.
import pyttsx3
engine = pyttsx3.init()
engine.say("Hello! This is an automated voice.")
engine.runAndWait()
5. Automate WhatsApp Messages
Sends WhatsApp messages using pywhatkit.
import pywhatkit
pywhatkit.sendwhatmsg("+1234567890", "Hello, this is an automated message!", 14, 30)
🔹 Tip: This will open WhatsApp Web at 2:30 PM and send the message.
6. Download YouTube Videos
Downloads YouTube videos using pytube.
from pytube import YouTube
url = "https://www.youtube.com/watch?v=your_video_id"
yt = YouTube(url)
yt.streams.get_highest_resolution().download()
print("Download Complete!")
7. Auto Organize Files
Organizes files into folders based on file type.
import os
import shutil
folder_path = "/path/to/downloads"
file_types = {
"Images": [".jpg", ".jpeg", ".png", ".gif"],
"Documents": [".pdf", ".docx", ".txt"],
"Videos": [".mp4", ".mkv"],
"Music": [".mp3", ".wav"]
for file in os.listdir(folder_path):
file_path = os.path.join(folder_path, file)
if os.path.isfile(file_path):
for folder, extensions in file_types.items():
if file.endswith(tuple(extensions)):
new_folder = os.path.join(folder_path, folder)
os.makedirs(new_folder, exist_ok=True)
shutil.move(file_path, new_folder)
print("Files organized successfully!")
8. Check Internet Speed
Measures internet speed using speedtest-cli.
import speedtest
st = speedtest.Speedtest()
download_speed = st.download() / 1_000_000
upload_speed = st.upload() / 1_000_000
print(f"Download Speed: {download_speed:.2f} Mbps")
print(f"Upload Speed: {upload_speed:.2f} Mbps")
9. Automate Website Status Check
Checks if a website is up or down.
import requests
url = "https://example.com"
try:
response = requests.get(url)
if response.status_code == 200:
print(f"{url} is UP!")
else:
print(f"{url} is DOWN!")
except requests.ConnectionError:
print(f"{url} is NOT REACHABLE!")
10. Auto Shutdown PC
Schedules a shutdown in 60 seconds.
import os
os.system("shutdown /s /t 60") # Windows
# os.system("shutdown -h +1") # Linux/Mac (1-minute delay)
11. Get Weather Updates
Fetches the current weather for any city using OpenWeatherMap API.
import requests
API_KEY = "your_api_key"
city = "New York"
url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric"
response = requests.get(url).json()
print(f"Weather in {city}: {response['weather'][0]['description']}, {response['main']['temp']}°C")
🔹 Tip: Get an API key from OpenWeather.
Would you like scripts for any specific use case? 😊