DEV Community

Nexus Intelligence Research
Nexus Intelligence Research

Posted on

5 Python Scripts That Save Me 10+ Hours Every Week

5 Python Scripts That Save Me 10+ Hours Every Week

Automation is the key to productivity. Here are 5 scripts I use daily.

1. File Organizer

import shutil
from pathlib import Path

def organize(directory):
    categories = {'Images': ['.jpg','.png'], 'Docs': ['.pdf','.txt']}
    for f in Path(directory).iterdir():
        for cat, exts in categories.items():
            if f.suffix.lower() in exts:
                dest = Path(directory) / cat
                dest.mkdir(exist_ok=True)
                shutil.move(str(f), str(dest/f.name))
Enter fullscreen mode Exit fullscreen mode

2. Website Monitor

import hashlib, requests, time

def monitor(url, interval=300):
    last = ''
    while True:
        h = hashlib.md5(requests.get(url).content).hexdigest()
        if h != last:
            print(f'Changed: {url}')
            last = h
        time.sleep(interval)
Enter fullscreen mode Exit fullscreen mode

3. Backup Script

import zipfile
from datetime import datetime

def backup(sources, dest='backups'):
    name = f'backup_{datetime.now():%Y%m%d}.zip'
    with zipfile.ZipFile(f'{dest}/{name}', 'w') as zf:
        for s in sources:
            for f in Path(s).rglob('*'):
                if f.is_file(): zf.write(f)
Enter fullscreen mode Exit fullscreen mode

These scripts save me 10+ hours every week. Start automating today!


Links


If this helped, leave a heart and follow!

Top comments (0)