I run a one-person tech shop. Every part of the business is held together by small Python scripts that do the boring stuff so I can do the interesting stuff. No framework. No cloud platform. Just Python's standard library and a cron scheduler.
Here are five patterns from my daily workflow that you can copy in five minutes each.
1. File organizer by extension
Downloads folder is chaos after a month. Twenty lines of stdlib fixes it:
import os, shutil
from pathlib import Path
MAPPING = {'.jpg': 'Images', '.pdf': 'Docs', '.zip': 'Archives', '.py': 'Code'}
for f in Path.home().joinpath('Downloads').iterdir():
if f.is_file():
folder = MAPPING.get(f.suffix.lower(), 'Misc')
dest = Path.home() / folder / f.name
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.move(str(f), str(dest))
2. Batch renamer with dry-run
Renaming 200 photos by hand is a recipe for regret. Always print first, move after:
import os, re
from pathlib import Path
folder = Path('photos')
for i, f in enumerate(sorted(folder.glob('*.jpg')), 1):
new = folder / f'IMG_{i:03d}.jpg'
print(f'DRY RUN: {f.name} -> {new.name}') # verify, then uncomment:
# f.rename(new)
3. Excel report generator
Clients love spreadsheets. Generate them, don't type them:
import csv, datetime
rows = [['Date', 'Revenue', 'Cost'], [datetime.date.today().isoformat(), 1200, 400]]
with open('report.csv', 'w', newline='') as f:
csv.writer(f).writerows(rows)
4. Price monitor with alerts
Want to know when that GPU drops $200? Poll the page, diff the price, email yourself:
import urllib.request, re
html = urllib.request.urlopen('https://example.com/item').read().decode()
price = re.search(r'\$([0-9,]+)', html).group(1)
# compare with last known price, send email if lower
5. Log rotator
Servers grow logs like weeds. Keep only the last 7 days:
import glob, os, time
for f in glob.glob('logs/*.log'):
if time.time() - os.path.getmtime(f) > 7 * 86400:
os.remove(f)
The full cookbook
These five are the appetizers. The complete Python Automation Cookbook contains 50 production-ready scripts — email automation (digests, forwarders, auto-responders), system monitoring, backup pipelines, Excel wrangling, git workflow helpers, API health pollers, and more. Each script is a single self-contained file with comments, so you can copy-paste and adapt without reading a novel first.
Get the full pack: https://qiliang.gumroad.com/l/tsslu ($24, 50 scripts + README, lifetime updates)
What's your most-used automation script? Drop it in the comments — I'm always collecting good ones.
Top comments (0)