DEV Community

Anna lilith
Anna lilith

Posted on

5 Python Scripts That Save Me 10 Hours a Week

Here are 5 Python scripts I use daily to automate repetitive tasks.

1. Batch File Renamer

import os
from pathlib import Path

def batch_rename(path, pattern, replacement):
    for f in Path(path).iterdir():
        if f.is_file():
            new_name = f.name.replace(pattern, replacement)
            f.rename(f.parent / new_name)

batch_rename("./photos", "IMG_", "vacation_")
Enter fullscreen mode Exit fullscreen mode

2. Bulk Image Resizer

from PIL import Image
from pathlib import Path

def resize_images(path, max_width=800):
    for f in Path(path).glob("*.jpg"):
        img = Image.open(f)
        if img.width > max_width:
            ratio = max_width / img.width
            img.resize((max_width, int(img.height * ratio))).save(f)
Enter fullscreen mode Exit fullscreen mode

3. CSV Merger

import pandas as pd
from pathlib import Path

def merge_csvs(folder, output="merged.csv"):
    frames = [pd.read_csv(f) for f in Path(folder).glob("*.csv")]
    pd.concat(frames).to_csv(output, index=False)
Enter fullscreen mode Exit fullscreen mode

4. Email Verifier

import dns.resolver

def verify_email(email):
    domain = email.split("@")[1]
    try:
        dns.resolver.resolve(domain, "MX")
        return True
    except:
        return False
Enter fullscreen mode Exit fullscreen mode

5. Website Change Monitor

import requests, hashlib, time

def monitor(url, interval=300):
    last_hash = ""
    while True:
        resp = requests.get(url)
        current = hashlib.md5(resp.text.encode()).hexdigest()
        if current != last_hash:
            print(f"Change detected at {url}")
            last_hash = current
        time.sleep(interval)
Enter fullscreen mode Exit fullscreen mode

All these scripts and 390+ more are available at https://create-openings-unsigned-garden.trycloudflare.com. BTC/XMR accepted.

Top comments (0)