Skip to content

22MH1A42G1/Python-File-Automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βš™οΈ Python File Automation

A browser-based file automation tool built with Python + Flask that lets you upload, rename, convert, organise, and download files β€” all from a sleek dark-themed web UI. Every automation operation is logged to a PostgreSQL / SQLite database for full task-history tracking.


πŸ“‘ Table of Contents


✨ Features

Feature Description
πŸ“€ Upload Files Drag-and-drop or browse to upload one or more files
✏️ Rename Files Batch-rename uploaded files with a custom prefix (prefix_1.ext, prefix_2.ext, …)
πŸ”„ CSV β†’ JSON Convert every .csv file into a pretty-printed .json file automatically
πŸ“‚ Organise Files Sort files into category sub-folders (images/, documents/, audio/, video/, data/, code/, archives/, others/)
πŸ“‹ Browse & Download View uploaded and processed files; download any processed file with one click
πŸ—‘οΈ Clear Folders Clear the uploads or processed folder independently
πŸ—„οΈ Task History Every automation operation is recorded in the database with filename, task type, and status

πŸ—οΈ System Architecture

flowchart TD
    subgraph Browser["🌐 Browser (Client)"]
        UI["HTML / CSS / JS\nSingle-Page UI"]
    end

    subgraph Flask["🐍 Flask Web Server"]
        direction TB
        R_Index["GET  /"]
        R_Upload["POST /upload"]
        R_Files["GET  /files"]
        R_Rename["POST /rename"]
        R_CSV["POST /csv-to-json"]
        R_Org["POST /organize"]
        R_DL["GET  /download/<file>"]
        R_ClearU["POST /clear-uploads"]
        R_ClearP["POST /clear-processed"]
        R_Tasks["GET  /tasks"]
        R_SeedDB["POST /seed-db"]
    end

    subgraph Automation["βš™οΈ Automation Modules"]
        M_Rename["rename_files.py\nSequential renaming"]
        M_CSV["csv_to_json.py\nCSV β†’ JSON conversion"]
        M_Sort["sort_files.py\nExtension-based sorting"]
    end

    subgraph FileSystem["πŸ’Ύ File System"]
        FS_Up["uploads/\n(raw input files)"]
        FS_Proc["processed/\nβ”œβ”€β”€ images/\nβ”œβ”€β”€ documents/\nβ”œβ”€β”€ audio/\nβ”œβ”€β”€ video/\nβ”œβ”€β”€ data/\nβ”œβ”€β”€ code/\nβ”œβ”€β”€ archives/\n└── others/"]
    end

    subgraph Database["πŸ—„οΈ Database (SQLAlchemy)"]
        DB[("PostgreSQL / SQLite\nautomation_tasks table\n─────────────────\nid Β· filename\ntask_type Β· status\ncreated_at")]
    end

    UI -- "HTTP REST (JSON/multipart)" --> Flask
    R_Upload --> FS_Up
    R_Rename --> M_Rename --> FS_Proc
    R_CSV    --> M_CSV    --> FS_Proc
    R_Org    --> M_Sort   --> FS_Proc
    R_Files  --> FS_Up & FS_Proc
    R_DL     --> FS_Proc
    FS_Up    -. "reads" .-> M_Rename & M_CSV & M_Sort
    R_Tasks  --> Database
    R_SeedDB --> Database
    M_Rename -. "logs task" .-> Database
    M_CSV    -. "logs task" .-> Database
    M_Sort   -. "logs task" .-> Database
Loading

🎯 Use Case Diagram

graph LR
    User(("πŸ‘€ User"))

    User --> UC1["πŸ“€ Upload Files\n(drag-and-drop / browse)"]
    User --> UC2["✏️ Rename Files\n(custom prefix)"]
    User --> UC3["πŸ”„ Convert CSV to JSON"]
    User --> UC4["πŸ“‚ Organise Files by Type"]
    User --> UC5["πŸ“‹ Browse Files"]
    User --> UC6["⬇️ Download Processed File"]
    User --> UC7["πŸ—‘οΈ Clear Uploads / Processed"]
    User --> UC8["πŸ—„οΈ View Task History"]

    UC2 -. "requires" .-> UC1
    UC3 -. "requires" .-> UC1
    UC4 -. "requires" .-> UC1
    UC6 -. "requires" .-> UC5
    UC8 -. "reads from" .-> DB[("πŸ—„οΈ Database")]

    UC2 -. "logs to" .-> DB
    UC3 -. "logs to" .-> DB
    UC4 -. "logs to" .-> DB

    style User fill:#6c63ff,color:#fff,stroke:#6c63ff
    style UC1 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC2 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC3 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC4 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC5 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC6 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC7 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style UC8 fill:#1a1d27,color:#e2e8f0,stroke:#2a2d3e
    style DB  fill:#0f3460,color:#e2e8f0,stroke:#1a6aab
Loading

πŸ–ΌοΈ Screenshots

1 Β· Upload Files

Drag-and-drop files into the drop zone or browse your filesystem. A live file preview shows selected files before uploading.

Upload Files tab


2 Β· Rename Files

Enter a prefix and click Rename Files. Every file in uploads/ is copied to processed/ with the pattern <prefix>_N.ext.

Rename Files tab


3 Β· CSV β†’ JSON Conversion

Click Convert CSV β†’ JSON to transform all uploaded .csv files into structured, pretty-printed JSON arrays stored in processed/.

CSV to JSON tab


4 Β· Organise Files by Type

Click Organise Files to automatically sort every uploaded file into a named sub-folder inside processed/ based on its extension.

Organise Files tab


5 Β· Browse & Download Files

See both uploads/ and processed/ content at a glance. Download any processed file with one click.

Browse Files tab


πŸ› οΈ Tech Stack

Layer Technology
Backend Python 3, Flask
Database PostgreSQL (production) / SQLite (development) via SQLAlchemy ORM
File handling os, shutil, csv, json (stdlib)
Frontend Vanilla HTML5, CSS3 (custom dark theme), JavaScript (Fetch API)
Deployment Vercel (serverless)
Security werkzeug.utils.secure_filename, path-traversal guard on downloads

πŸ—„οΈ Database Schema

The automation_tasks table is used to record every file operation. Schema shown in PostgreSQL syntax; for SQLite, replace SERIAL with INTEGER (SQLite auto-increments integer primary keys automatically).

-- PostgreSQL
CREATE TABLE IF NOT EXISTS automation_tasks (
    id         SERIAL PRIMARY KEY,
    filename   VARCHAR(255)  NOT NULL,
    task_type  VARCHAR(50)   NOT NULL,   -- 'rename' | 'csv_to_json' | 'organize'
    status     VARCHAR(20)   NOT NULL,   -- 'processing' | 'completed' | 'failed'
    created_at TIMESTAMP     DEFAULT CURRENT_TIMESTAMP
);

-- SQLite equivalent
CREATE TABLE IF NOT EXISTS automation_tasks (
    id         INTEGER PRIMARY KEY AUTOINCREMENT,
    filename   TEXT          NOT NULL,
    task_type  TEXT          NOT NULL,
    status     TEXT          NOT NULL,
    created_at TIMESTAMP     DEFAULT CURRENT_TIMESTAMP
);

πŸš€ Getting Started

Prerequisites

  • Python 3.9+
  • pip
  • PostgreSQL (optional β€” SQLite used automatically when DATABASE_URL is not set)

Installation

# 1 Β· Clone the repository
git clone https://github.com/22MH1A42G1/Python-File-Automation.git
cd Python-File-Automation/file_automation_web

# 2 Β· Install dependencies
pip install -r requirements.txt

# 3 Β· (Optional) Set your database URL
#     Skip this step to use SQLite locally; required for PostgreSQL / Vercel
export DATABASE_URL="postgresql://user:password@host:5432/dbname"

# 4 Β· Create the database table β€” PostgreSQL only (run once)
#     SQLite users: skip this step; the table is created automatically by SQLAlchemy.
psql $DATABASE_URL -c "
  CREATE TABLE IF NOT EXISTS automation_tasks (
    id         SERIAL PRIMARY KEY,
    filename   VARCHAR(255) NOT NULL,
    task_type  VARCHAR(50)  NOT NULL,
    status     VARCHAR(20)  NOT NULL,
    created_at TIMESTAMP    DEFAULT CURRENT_TIMESTAMP
  );"

# 5 Β· Run the development server
python app.py

Open your browser at http://127.0.0.1:5000 πŸŽ‰

Dependencies (requirements.txt)

flask
werkzeug
sqlalchemy
psycopg2-binary

πŸ“‘ API Reference

Method Endpoint Description
GET / Serve the web UI
POST /upload Upload one or more files (multipart form)
GET /files List files in uploads/ and processed/
POST /rename Rename files β€” body: {"prefix": "my_prefix"}
POST /csv-to-json Convert all CSV files in uploads to JSON
POST /organize Organise files into category sub-folders
GET /download/<path:filename> Download a processed file
POST /clear-uploads Delete all files from uploads/
POST /clear-processed Delete all files/folders from processed/
GET /tasks Retrieve all automation task records from the database
POST /seed-db Insert a demo task record and mark it completed (dev only)

πŸ“ Project Structure

Python-File-Automation/
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ vercel.json                  # Vercel serverless deployment config
└── file_automation_web/
    β”œβ”€β”€ app.py                   # Flask application & route definitions (local dev)
    β”œβ”€β”€ requirements.txt         # Python dependencies
    β”œβ”€β”€ api/
    β”‚   └── index.py             # Vercel serverless entry-point (includes DB routes)
    β”œβ”€β”€ automation/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ rename_files.py      # Batch-rename logic
    β”‚   β”œβ”€β”€ csv_to_json.py       # CSV β†’ JSON conversion logic
    β”‚   └── sort_files.py        # Extension-based file organiser
    β”œβ”€β”€ static/
    β”‚   β”œβ”€β”€ style.css            # Dark-theme stylesheet
    β”‚   └── script.js            # Frontend JS (Fetch API interactions)
    └── templates/
        └── index.html           # Single-page application template

πŸ“‚ File Category Mapping

Category Extensions
πŸ–ΌοΈ images .jpg .jpeg .png .gif .bmp .svg .webp .tiff
πŸ“„ documents .pdf .doc .docx .txt .xls .xlsx .ppt .pptx .odt
🎡 audio .mp3 .wav .aac .flac .ogg .m4a .wma
🎬 video .mp4 .avi .mov .mkv .wmv .flv .webm
πŸ“Š data .csv .json .xml .sql .db .sqlite
πŸ’» code .py .js .ts .html .css .java .cpp .c .go .rb
πŸ—œοΈ archives .zip .rar .tar .gz .7z .bz2
❓ others Everything else

πŸͺͺ License

This project is open source. Feel free to use, modify, and distribute.

About

File automation means using Python to automatically perform tasks on files instead of doing them manually. https://python-file-automation.vercel.app;

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors