The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomePythonStory
    Python

    Automate the Boring Stuff with Python: 3 Modern Scripts (2026)

    H

    By Huzi

    File #48 · 3 min read

    Python automation is how the boring stuff gets done: this 2026 set carries the downloads-folder organiser, the async scraper and the bulk image resizer — the three scripts that earn their place on a hard drive — plus the one command that stitches them into a pipeline. Earlier versions of this post carried five scripts; two of them mostly duplicated library documentation, so they are gone.

    The quick answer: Python 3.15 in a uv venv, three libraries — httpx, beautifulsoup4, Pillow — and the scripts below cover organising, scraping and resizing. Together they quietly become the back office of a small shop.

    Setup, once

    Python 3.15 from python.org, then a virtual environment with uv, the fast modern installer:

    uv venv
    source .venv/bin/activate  # Windows: .venv\Scripts\activate
    uv pip install httpx beautifulsoup4 Pillow
    

    1. Tame the Downloads folder with pathlib

    from pathlib import Path
    from shutil import move
    
    def organize(directory: Path) -> None:
        for file in directory.iterdir():
            if file.is_file() and file.suffix:
                target = directory / file.suffix.lstrip(".").lower()
                target.mkdir(exist_ok=True)
                move(file, target / file.name)
    
    organize(Path.home() / "Downloads")
    

    Sixty files of chaos become folders named pdf, zip and xlsx. pathlib keeps the code cross-platform — Path.home() resolves correctly on Windows, macOS and Linux without a single conditional.

    2. Scrape without the wait, with httpx

    import asyncio, httpx
    from bs4 import BeautifulSoup
    
    async def fetch_headlines() -> list[str]:
        async with httpx.AsyncClient(timeout=10.0) as client:
            r = await client.get("https://news.ycombinator.com")
            r.raise_for_status()
        soup = BeautifulSoup(r.text, "html.parser")
        return [a.get_text(strip=True) for a in soup.select("span.titleline > a")]
    
    for i, title in enumerate(asyncio.run(fetch_headlines()), 1):
        print(f"{i}. {title}")
    

    The synchronous requests habit works, but the async habit scales: point the same AsyncClient at a list of two hundred URLs with asyncio.gather and the loop finishes before the kettle does.

    3. Resize a whole folder with Pillow

    from pathlib import Path
    from PIL import Image
    
    def resize_all(source: Path, output: Path, width: int) -> None:
        output.mkdir(parents=True, exist_ok=True)
        for img_path in source.glob("*"):
            if img_path.suffix.lower() in {".png", ".jpg", ".jpeg", ".webp"}:
                with Image.open(img_path) as img:
                    ratio = width / img.width
                    new = img.resize((width, int(img.height * ratio)),
                                     Image.Resampling.LANCZOS)
                    new.save(output / img_path.name)
    

    The with block matters more than it looks — it releases the file handle even when an image is corrupt. LANCZOS is the resampling filter that keeps text in screenshots readable. Point it at a source_images folder, run it once, and every Reel-sized asset your shop needs is ready in seconds.

    Stitch them together

    The script The job The hero
    Downloads organiser Chaos into folders by file type pathlib
    Async scraper Headlines without the wait httpx with BeautifulSoup
    Bulk resizer Reel-sized assets in seconds Pillow with LANCZOS

    These three are LEGO bricks: scrape a page of prices, resize the product photos, organise the output by date, and you have the bones of an e-commerce back office in an afternoon.

    An afternoon of scripting buys back every evening after it. Reclaimed evenings are the raw material of travel — HTG Travel sees the results each season: shops that ran themselves while their owners finally took the weekend.

    Pro tip: Wrap the scraper in a try/except httpx.HTTPError — the network's worst day becomes a log line instead of a crash. Schedule what survives with cron on Linux or Task Scheduler on Windows, and the boring stuff simply stops appearing on your desk.

    When your cron job survives a restart, thank reliability engineering; when Gaza's coders keep a pipeline alive through weeks of cut power, that is the discipline automation only imitates. Sudan's coders automated around war itself — schedulers that queue uploads for whenever the internet returns — may their scripts soon run in a country boring enough for ordinary work.

    Every hour a script saves is an hour with your name on it, and hours become weekends. Automate the boring; keep the mountains manual — when you are ready to move, HTG Travel will book the Thursday-to-Sunday northern road trip your calendar keeps deleting, or a remote month somewhere greener. WhatsApp +92 317 5054959.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Luxury Heavy Embroidered EID Lawn 3-Pc Suit with Digital Silk Dupatta (Formal Wear)

    Luxury Heavy Embroidered EID Lawn 3-Pc Suit with Digital Silk Dupatta (Formal Wear)

    PKR 6900

    Chikankari Embroidered EID Lawn Suit 3-Pc | Digital Printed Chiffon Dupatta (2025)

    Chikankari Embroidered EID Lawn Suit 3-Pc | Digital Printed Chiffon Dupatta (2025)

    PKR 4800

    Heavy Embroidered Lawn Suit 3-Pc (2024) | Digital Print Diamond Organza Dupatta

    Heavy Embroidered Lawn Suit 3-Pc (2024) | Digital Print Diamond Organza Dupatta

    PKR 4700

    Elegant Printed Swiss Lawn Dress 3-Pc | Digital Print Silk Dupatta (2024)

    Elegant Printed Swiss Lawn Dress 3-Pc | Digital Print Silk Dupatta (2024)

    PKR 3950

    Luxurious Schiffli Embroidered Lawn Suit 3-Pc | Heavy Embroidered Organza Dupatta (2025)

    Luxurious Schiffli Embroidered Lawn Suit 3-Pc | Heavy Embroidered Organza Dupatta (2025)

    PKR 6700

    Keep reading

    Related files

    Python
    English

    Getting Started with Python 3.13 for Absolute Beginners (2026)

    The strict quickstart: install Python 3.13 properly (including the Windows PATH trap), write and run your first script today, and know exactly what to learn in what order next.

    By HuziFile #191

    Read
    Python
    English

    Introduction to Python 3.13: The All-Purpose Language (2026)

    What Python actually is: an interpreted, whitespace-sensitive language whose readable syntax now runs everything from Sunday scripts to the AI stack, with 3.13's speed work humming under the hood.

    By HuziFile #280

    Read
    Python
    English

    The Serpent's Grace: The Ultimate Python 3.13 Guide (2026)

    The practice-path way to learn Python: a project ladder from a script that saves you an hour to a deployed AI agent, plus the 2026 tooling — uv, ruff, pyright, pytest — that keeps the climb sane.

    By HuziFile #421

    Read
    Python
    English

    Mastering Python Decorators: A Practical Guide (2026)

    Decorators from the inside out: the wrapper anatomy, functools.wraps, decorator factories that take arguments, the stdlib caches you should not hand-roll, and typing them properly with ParamSpec.

    By HuziFile #299

    Read
    C#
    English

    C# Essential Guide to Modern Programming Techniques (2026)

    C# 15 on .NET 11 in practice: primary constructors, records with collection expressions, switch-expression pattern matching, async streams, and Native AOT publishing for milliseconds-cold binaries.

    By HuziFile #90

    Read
    Programming
    English

    The Modern Craftsman: Essential Guide to C++ (2026)

    What modern actually means now: std::print and structured bindings, smart pointers for ownership, ranges pipelines, concepts, and std::expected error handling in C++23.

    By HuziFile #89

    Read
    Back to the archive