Skip to content

Repository files navigation

Python Automation Scripts

10 useful Python automation scripts for everyday file, data, and system tasks.

Buy Me a Coffee


Scripts Overview

#ScriptDescription
1image-resizer.pyBulk resize images using PIL
2csv-to-json.pyConvert CSV files to JSON
3folder-sync.pySync two folders, mirror deletions
4text-search.pyRecursive text search across files with context lines
5url-checker.pyCheck if URLs are alive (HTTP status checker)
6file-splitter.pySplit large files into chunks
7date-organizer.pyOrganize files into YYYY/MM/DD folders by date modified
8color-extract.pyExtract dominant colors from images
9json-to-csv.pyFlatten nested JSON to CSV
10system-cleaner.pyFind and clean temp files, cache, empty dirs

Requirements

Most scripts use only the Python standard library. A few require extra packages:

pip install pillow requests numpy
  • image-resizer.py → Pillow
  • color-extract.py → Pillow, numpy
  • url-checker.py → requests

Usage Examples

1. image-resizer.py — Bulk Resize Images

# Resize all images in a directory to 800x600 (maintaining aspect ratio)
python image-resizer.py ./photos --width 800 --height 600
# Resize to 50% of original size
python image-resizer.py ./photos --percent 50
# Specify output directory
python image-resizer.py ./photos --width 1920 --output ./wallpapers

2. csv-to-json.py — Convert CSV to JSON

# Basic conversion
python csv-to-json.py data.csv
# Pretty-print output
python csv-to-json.py data.csv --pretty
# Custom delimiter (e.g. tab-separated)
python csv-to-json.py data.tsv --delimiter $'\t'# Specify output file
python csv-to-json.py data.csv --output data.json --pretty

3. folder-sync.py — Sync Two Folders

# Sync source to replica (creates replica, copies new/modified, deletes extra files)
python folder-sync.py ./original ./backup
# Dry run to preview changes
python folder-sync.py ./original ./backup --dry-run
# Exclude certain patterns
python folder-sync.py ./project ./backup --exclude .git --exclude node_modules
# Ignore hidden files
python folder-sync.py ./src ./dst --ignore-hidden

4. text-search.py — Recursive Text Search

# Basic search with 2 lines of context
python text-search.py "TODO" ./src
# Case-insensitive search in Python files only, 5 lines of context
python text-search.py "def main" ./ --ext py --context 5 --ignore-case
# Search with exclusions
python text-search.py "import os". --ext py --exclude venv --exclude .git
# Limit file size
python text-search.py "error" /var/log --context 3 --max-size 5

5. url-checker.py — HTTP Status Checker

# Check individual URLs
python url-checker.py https://google.com https://github.com
# Check from file
python url-checker.py --file urls.txt
# Concurrent checking with custom timeout
python url-checker.py --file urls.txt --concurrent 20 --timeout 5

6. file-splitter.py — Split Large Files

# Split text file every 10000 lines
python file-splitter.py huge-log.txt --lines 10000
# Split binary file into 50MB chunks
python file-splitter.py video.mp4 --size 50MB
# Custom prefix and keep CSV header in each chunk
python file-splitter.py data.csv --lines 5000 --prefix data_chunk

7. date-organizer.py — Organize Files by Date

# Preview organizing Downloads folder
python date-organizer.py ~/Downloads --dry-run
# Move files into YYYY/MM/DD folders by modification date
python date-organizer.py ./photos --move
# Use creation date instead
python date-organizer.py ./photos --move --date-created
# Exclude certain patterns
python date-organizer.py ~/Downloads --move --exclude .tmp

8. color-extract.py — Extract Dominant Colors

# Extract 5 dominant colors from an image
python color-extract.py photo.jpg
# Extract 10 colors in hex format only
python color-extract.py photo.jpg --colors 10 --format hex
# Process all PNGs in a directory
python color-extract.py ./images --glob *.png --colors 3

9. json-to-csv.py — Flatten Nested JSON to CSV

# Convert JSON array to CSV
python json-to-csv.py data.json
# Custom delimiter
python json-to-csv.py data.json --delimiter ';'# Specify output path
python json-to-csv.py data.json --output table.csv

10. system-cleaner.py — Clean Temp Files

# Scan for temp files (dry run)
python system-cleaner.py ~/Downloads
# Actually delete temp files older than 30 days
python system-cleaner.py ~/Downloads --clean --max-age 30
# Target specific extensions and remove empty dirs
python system-cleaner.py . --clean --ext .pyc --remove-empty
# Only delete files larger than 1MB
python system-cleaner.py /tmp --clean --ext .tmp --min-size 1MB

All scripts support --help

Every script has a detailed help screen:

python <script-name>.py --help

License

MIT — Free for personal and commercial use.

If you find these scripts useful, consider buying me a coffee! ☕


Support