As a developer, I'm always looking for ways to automate repetitive tasks. Here are 5 Python scripts that saved me 10 hours this week.
1. Automated File Organizer
This script automatically organizes files by type, date, or custom rules.
import os
import shutil
from pathlib import Path
def organize_files(directory, pattern="extension"):
path = Path(directory)
for file in path.iterdir():
if file.is_file():
if pattern == "extension":
ext = file.suffix.lower().lstrip(".") or "no_extension"
target = path / ext
elif pattern == "date":
import datetime
mtime = datetime.datetime.fromtimestamp(file.stat().st_mtime)
target = path / mtime.strftime("%Y-%m")
else:
continue
target.mkdir(exist_ok=True)
shutil.move(str(file), str(target / file.name))
print(f"Moved {file.name} -> {target.name}/")
# Usage: organize_files("/path/to/messy/folder")
Time saved: 30 minutes per week
2. Git Commit Message Generator
This script generates meaningful commit messages from your changes.
import subprocess
def generate_commit_message():
# Get staged changes
result = subprocess.run(["git", "diff", "--cached", "--stat"],
capture_output=True, text=True)
# Analyze changes
files_changed = result.stdout.count("|")
if files_changed == 1:
return "Update single file"
elif files_changed < 5:
return "Refactor multiple files"
else:
return "Major update across codebase"
Time saved: 15 minutes per day
3. Dependency Updater
This script checks for outdated dependencies and updates them.
import subprocess
import json
def check_outdated():
result = subprocess.run(["pip", "list", "--outdated", "--format=json"],
capture_output=True, text=True)
outdated = json.loads(result.stdout)
for pkg in outdated:
print(f"{pkg['name']}: {pkg['version']} -> {pkg['latest_version']}")
return outdated
# Usage: check_outdated()
Time saved: 20 minutes per week
4. API Documentation Generator
This script generates API docs from your code.
import inspect
def generate_api_docs(module):
docs = []
for name, obj in inspect.getmembers(module):
if inspect.isfunction(obj):
sig = inspect.signature(obj)
docs.append(f"## {name}{sig}")
docs.append(f"{obj.__doc__ or 'No documentation'}")
docs.append("")
return "\n".join(docs)
Time saved: 2 hours per project
5. Test Data Generator
This script generates realistic test data.
import random
import string
def generate_user_data(count=10):
users = []
for _ in range(count):
users.append({
"name": "".join(random.choices(string.ascii_lowercase, k=8)),
"email": f"{''.join(random.choices(string.ascii_lowercase, k=5))}@example.com",
"age": random.randint(18, 65),
"balance": round(random.uniform(0, 10000), 2),
})
return users
# Usage: users = generate_user_data(100)
Time saved: 1 hour per test suite
Total Time Saved: 10+ hours per week
These simple scripts have dramatically improved my productivity. The key is to identify repetitive tasks and automate them.
What tasks do you automate? Share in the comments!
Follow me for more Python automation tips and developer productivity strategies.
Top comments (0)