Python Automation Scripts (Real-World Projects)
Python is widely used for automation because of its simplicity and powerful libraries. Automation helps save time by reducing manual work.
In this tutorial, we will explore real-world Python automation scripts that you can build and add to your portfolio.
1. File Automation Scripts
Script: Organize files by extension
import os
import shutil
path = "./files"
for file in os.listdir(path):
ext = file.split('.')[-1]
folder = os.path.join(path, ext)
os.makedirs(folder, exist_ok=True)
shutil.move(os.path.join(path, file), folder)
2. Email Automation
Script: Send email using SMTP
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('your_email@gmail.com', 'password')
message = "Hello from Python"
server.sendmail('your_email@gmail.com', 'to_email@gmail.com', message)
server.quit()
3. Web Scraping Automation
Script: Extract website data
import requests
from bs4 import BeautifulSoup
url = "https://example.com"
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
for link in soup.find_all('a'):
print(link.get('href'))
4. Task Automation
Script: Open applications automatically
import os
os.system('notepad')
5. Data Automation
Script: Read and process CSV file
import csv
with open('data.csv') as f:
reader = csv.reader(f)
for row in reader:
print(row)
6. Advanced Automation Projects
1. WhatsApp automation using Selenium.
2. Auto login bot for websites.
3. Stock price alerts using APIs.
4. Automated report generation.
5. Social media posting bot.
7. Tools & Libraries for Automation
1. os, shutil → file operations
2. smtplib → email automation
3. requests → API calls
4. BeautifulSoup → web scraping
5. Selenium → browser automation
8. Best Practices
1. Handle exceptions properly.
2. Use environment variables for credentials.
3. Optimize scripts for performance.
4. Test scripts before deployment.
Conclusion
Python automation scripts can significantly improve productivity and reduce repetitive tasks.
Start with simple scripts and gradually move to advanced automation projects.
Codecrown