Skip to main content

Automating My Life with Python

Why spend 10 minutes doing it every day when you can spend 10 hours automating it once? (Just kidding. It pays off eventually.)

1. The File Organizer
#

I download a lot of files. My Downloads folder is a mess. I wrote a script to watch the folder and move files based on extension.

import os
import shutil

EXTENSIONS = {
    "Images": [".jpg", ".png", ".svg"],
    "Documents": [".pdf", ".docx", ".txt"],
    "Installers": [".deb", ".iso", ".zip"]
}

def organize():
    for filename in os.listdir("."):
        for folder, exts in EXTENSIONS.items():
            if filename.endswith(tuple(exts)):
                shutil.move(filename, folder)

2. Terminal Demo
#

Here is the script in action:

(Note: This is a placeholder demo. To replace it with your own recording:)

  1. Run asciinema rec demo.cast in your terminal.
  2. Run asciinema upload demo.cast.
  3. Copy the ID from the URL and update this shortcode.

3. Expense Tracking
#

I use pandas to parse my bank’s CSV export and categorize expenses automatically.

import pandas as pd

df = pd.read_csv("statement.csv")
food = df[df['description'].str.contains("UBER EATS|CAFE")]
print(f"Total Food: ${food['amount'].sum()}")
Tip: Run these scripts on a cron job or systemd timer so you never have to think about them.