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
- os → Interact with file system (list files, create folders)
- shutil → Move, copy, delete files
File Organizer Project (Explanation)
Core Logic
- Read all files from a directory
- Identify file type using extension
- Match extension with predefined categories
- Move file into corresponding folder
- If unmatched → move to "Others"
Code Breakdown
import osimport 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
- schedule → Scheduling tasks
- time → Delay execution
- plyer → Desktop notifications
- playsound → Audio alerts
Reminder Automation Project
Core Logic
- Create a function (task)
- Schedule it using schedule
- 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
- Modify the file organizer to handle .zip and .rar files and move them into an "Archives" folder.
- Change the source folder dynamically using user input instead of hardcoding it.
- Print total number of files moved after execution.
Intermediate Level
-
Add a condition:
Skip files larger than 50MB. - Instead of moving files, copy them using shutil.copy().
- Create a log file (log.txt) and store all moved file names.
Advanced Level
- Schedule the file organizer to run automatically every day at a specific time.
-
Add notification after file organization completes:
- Show number of files organized
-
Extend the reminder system:
- Add multiple reminders from a list
-
Example:
- "Drink Water"
- "Take Break"
- "Revise DSA"
Challenge Task
- Build a combined automation system:
- File organizer runs daily at 10 PM
- Reminder system runs every hour
- Show desktop notification when both tasks execute
.png)
.png)


