Thursday, 30 April 2026

April Python Bootcamp Day 18


 

Automation is where Python starts feeling powerful. Instead of manually repeating tasks—like organizing files or setting reminders—you write code once and let it run for you indefinitely.

This session covers two practical domains:

  • File Automation (organizing system files)
  • Task Automation (running scheduled tasks automatically)

Why Automation?

In real-world workflows, repetitive operations consume time and introduce human error. Automation helps to:

  • Eliminate manual effort
  • Improve consistency
  • Save time for high-value work
  • Build real-world applicable skills

Examples:

  • Organizing downloads folder automatically
  • Sending reminders or alerts
  • Running scripts at specific times

File Automation

What is File Automation?

File automation refers to programmatically managing and organizing files based on rules such as file type, size, or naming patterns.

Example:

  • Move .jpg files → Images folder
  • Move .pdf files → Documents folder

Tools Required

  1. os → Interact with file system (list files, create folders)
  2. shutil → Move, copy, delete files

File Organizer Project (Explanation)

Core Logic

  1. Read all files from a directory
  2. Identify file type using extension
  3. Match extension with predefined categories
  4. Move file into corresponding folder
  5. If unmatched → move to "Others"

Code Breakdown

import os
import shutil

# Target folder
source_folder = "C:/Users/91707/Downloads"

# File Type mapping
FILE_TYPES = {
"Images": [".jpg",".png",".jpeg"],
"Documents": [".pdf",".txt",".csv",".docx"],
"Videos": [".mp4",".mkv"]
}

def organize_files():
for file in os.listdir(source_folder):
file_path = os.path.join(source_folder, file)

# Skip folders
if os.path.isdir(file_path):
    continue

_, ext = os.path.splitext(file)

moved = False

for folder, extensions in FILE_TYPES.items():
    if ext.lower() in extensions:
    dest_folder = os.path.join(source_folder, folder)

os.makedirs(dest_folder, exist_ok=True)

shutil.move(file_path, os.path.join(dest_folder, file))
print(f"Moved {file} -> {folder}")
moved = True
break

if not moved:
    others = os.path.join(source_folder, "Others")
    os.makedirs(others, exist_ok=True)
    shutil.move(file_path, os.path.join(others, file))
    print(f"Moved {file} -> Others")

organize_files()

Key Concepts Used

  • os.listdir() → List files in directory
  • os.path.join() → Safe path handling
  • os.makedirs(..., exist_ok=True) → Create folder if not exists
  • os.path.splitext() → Extract extension
  • shutil.move() → Move file

Task Automation

What is Task Automation?

Running a function automatically at a defined interval or specific time.

Examples:

  • Daily study reminder
  • Water intake alert
  • Running scripts at fixed intervals

Tools Required

  1. schedule → Scheduling tasks
  2. time → Delay execution
  3. plyer → Desktop notifications
  4. playsound → Audio alerts

Reminder Automation Project

Core Logic

  1. Create a function (task)
  2. Schedule it using schedule
  3. Run infinite loop to check pending tasks

Code

import schedule
import time
from playsound import playsound
from plyer import notification


def reminder(msg):
    print(f"Reminder: {msg}")

    notification.notify(
        title="Reminder",
        message=msg,
        timeout=5
    )

try:
    playsound("alert.mp3")
except:
    print("Sound file not found")

# Schedule tasks
schedule.every(4).seconds.do(reminder, "Drink Water")
schedule.every().day.at("18:40").do(reminder, "Study Python")

print("Running reminder bot...")

while True:
    schedule.run_pending()
    time.sleep(1)



Important Concepts

1. Function as Task

You pass a function to schedule:

schedule.every(4).seconds.do(reminder, "Drink Water")

2. Infinite Loop

Keeps checking scheduled tasks:

while True:
    schedule.run_pending()
    time.sleep(1)

3. Real-Time Automation

  • Runs continuously
  • Executes tasks at correct timing

Real-World Use Cases

  • Auto file sorter (Downloads, Desktop)
  • Backup system
  • Notification bots
  • Cron-like automation using Python
  • Personal productivity tools

Assignment Questions

Beginner Level

  1. Modify the file organizer to handle .zip and .rar files and move them into an "Archives" folder.
  2. Change the source folder dynamically using user input instead of hardcoding it.
  3. Print total number of files moved after execution.

Intermediate Level

  1. Add a condition:
    Skip files larger than 50MB.
  2. Instead of moving files, copy them using shutil.copy().
  3. Create a log file (log.txt) and store all moved file names.

Advanced Level

  1. Schedule the file organizer to run automatically every day at a specific time.
  2. Add notification after file organization completes:
    • Show number of files organized
  3. Extend the reminder system:
    • Add multiple reminders from a list
    • Example:
      • "Drink Water"
      • "Take Break"
      • "Revise DSA"

Challenge Task

  1. Build a combined automation system:
  • File organizer runs daily at 10 PM
  • Reminder system runs every hour
  • Show desktop notification when both tasks execute

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (255) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (29) Azure (10) BI (10) Books (262) Bootcamp (11) C (78) C# (12) C++ (83) Course (87) Coursera (300) Cybersecurity (30) data (5) Data Analysis (32) Data Analytics (22) data management (15) Data Science (354) Data Strucures (17) Deep Learning (159) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (19) Finance (10) flask (4) flutter (1) FPL (17) Generative AI (73) Git (10) Google (51) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (42) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (293) Meta (24) MICHIGAN (5) microsoft (11) Nvidia (8) Pandas (14) PHP (20) Projects (33) pytho (1) Python (1334) Python Coding Challenge (1132) Python Mathematics (1) Python Mistakes (51) Python Quiz (492) Python Tips (5) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (19) SQL (49) Udemy (18) UX Research (1) web application (11) Web development (8) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)