Every developer has repetitive tasks that eat into productive time. File organization, data extraction, email sending, PDF merging, and system checks — these are not complex problems, but they are time-consuming when done manually.
This guide gives you 5 production-ready Python scripts that you can run today. Each script solves a real problem, uses only standard libraries or common pip packages, and includes error handling so it does not break in the real world.
Whether you are a developer in Hyderabad, a freelancer in Mumbai, or a tech team in Milan or Rome, these scripts will fit into your workflow immediately.
1. Smart File Organizer — Clean Your Downloads Folder Automatically
Your Downloads folder is a mess. Everyone's is. This script sorts files by extension into categorized folders.
import os
import shutil
from pathlib import Path
DOWNLOADS = Path.home() / "Downloads"
CATEGORIES = {
"Images": [".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg"],
"Documents": [".pdf", ".docx", ".txt", ".xlsx", ".pptx"],
"Archives": [".zip", ".tar", ".gz", ".rar", ".7z"],
"Code": [".py", ".js", ".html", ".css", ".json", ".yaml"],
"Videos": [".mp4", ".mov", ".avi", ".mkv"],
}
def organize_downloads():
for file in DOWNLOADS.iterdir():
if file.is_file():
ext = file.suffix.lower()
moved = False
for folder, extensions in CATEGORIES.items():
if ext in extensions:
dest = DOWNLOADS / folder
dest.mkdir(exist_ok=True)
shutil.move(str(file), str(dest / file.name))
moved = True
break
if not moved:
other = DOWNLOADS / "Others"
other.mkdir(exist_ok=True)
shutil.move(str(file), str(other / file.name))
print("Downloads organized successfully.")
if __name__ == "__main__":
organize_downloads()
2. Web Scraping with Error Recovery
import requests
from bs4 import BeautifulSoup
import time
import json
def scrape_with_retry(url, retries=3, delay=2):
headers = {"User-Agent": "Mozilla/5.0 (compatible; Bot/1.0)"}
for attempt in range(retries):
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
return response.text
except requests.RequestException as e:
print(f"Attempt {attempt + 1} failed: {e}")
if attempt < retries - 1:
time.sleep(delay * (attempt + 1))
return None
def extract_article_links(html, base_url):
soup = BeautifulSoup(html, "html.parser")
links = []
for a in soup.find_all("a", href=True):
href = a["href"]
if href.startswith("/"):
href = base_url + href
if base_url in href:
links.append({"title": a.get_text(strip=True), "url": href})
return links
3. Bulk Email Sender with Personalization
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import csv
import time
SMTP_SERVER = "smtp.gmail.com"
SMTP_PORT = 465
SENDER_EMAIL = "your-email@gmail.com"
APP_PASSWORD = "your-app-password"
def send_email(to_email, name, company, subject, template):
msg = MIMEMultipart()
msg["From"] = SENDER_EMAIL
msg["To"] = to_email
msg["Subject"] = subject
body = template.replace("{name}", name).replace("{company}", company)
msg.attach(MIMEText(body, "plain", "utf-8"))
try:
with smtplib.SMTP_SSL(SMTP_SERVER, SMTP_PORT) as server:
server.login(SENDER_EMAIL, APP_PASSWORD)
server.send_message(msg)
print(f"Sent to {to_email}")
return True
except Exception as e:
print(f"Failed: {e}")
return False
def bulk_send(csv_file, subject, template, delay=5):
with open(csv_file, "r", encoding="utf-8") as f:
reader = csv.DictReader(f)
for row in reader:
success = send_email(row["email"], row["name"], row["company"], subject, template)
if success:
time.sleep(delay)
4. PDF Merger and Splitter
from PyPDF2 import PdfMerger, PdfReader, PdfWriter
from pathlib import Path
def merge_pdfs(input_files, output_file):
merger = PdfMerger()
for pdf in input_files:
merger.append(pdf)
merger.write(output_file)
merger.close()
print(f"Merged into {output_file}")
def split_pdf(input_file, output_prefix, pages_per_split=10):
reader = PdfReader(input_file)
total_pages = len(reader.pages)
for start in range(0, total_pages, pages_per_split):
writer = PdfWriter()
end = min(start + pages_per_split, total_pages)
for i in range(start, end):
writer.add_page(reader.pages[i])
output_path = f"{output_prefix}_part{start//pages_per_split + 1}.pdf"
with open(output_path, "wb") as f:
writer.write(f)
print(f"Saved {output_path} ({start+1}-{end})")
5. System Health Monitor
import psutil
import datetime
import json
def check_system_health():
cpu = psutil.cpu_percent(interval=1)
memory = psutil.virtual_memory()
disk = psutil.disk_usage("/")
boot_time = datetime.datetime.fromtimestamp(psutil.boot_time())
health = {
"timestamp": datetime.datetime.now().isoformat(),
"cpu_percent": cpu,
"memory_percent": memory.percent,
"memory_available_gb": round(memory.available / (1024**3), 2),
"disk_percent": disk.percent,
"disk_free_gb": round(disk.free / (1024**3), 2),
"uptime_hours": round((datetime.datetime.now() - boot_time).total_seconds() / 3600, 2),
}
alerts = []
if cpu > 80:
alerts.append(f"CPU usage is {cpu}%")
if memory.percent > 85:
alerts.append(f"Memory usage is {memory.percent}%")
if disk.percent > 90:
alerts.append(f"Disk usage is {disk.percent}%")
if alerts:
print("ALERTS:", *alerts, sep="\n - ")
else:
print("System healthy.")
with open("health_log.json", "a", encoding="utf-8") as f:
f.write(json.dumps(health) + "\n")
return health
if __name__ == "__main__":
check_system_health()
Key Takeaways
- File organization, web scraping, email sending, PDF handling, and system monitoring are the 5 most common automation needs for developers and small businesses.
- Python's standard library plus a few pip packages covers all of them.
- Error handling and retry logic are not optional — they separate scripts that work once from scripts that run reliably.
- These scripts work on any machine: a MacBook in Bangalore, a Windows laptop in Delhi, or a VPS in Frankfurt.
- The next step is wrapping them in an agent framework so they run autonomously based on triggers.
Tharun Ramagiri is a web developer, security researcher, and AI enthusiast building autonomous AI agents. Follow the tarunai project.
Top comments (0)