Projects
Projects
Table of Contents
1. File Organizer
2. Email Automation
3. Web Scraper
4. Expense Tracker
5. Weather App
Instruction:
1. Setup:
2. Project Development:
3. Submission
Objective
The objective of these exercises is to enhance your Python programming skills by working on practical automation
projects. Each project is designed to help you:
By completing these projects, you will build a solid foundation in Python programming and be better prepared to
tackle more complex automation tasks in the future.
Projects
1. File Organizer
Objective
Create a Python script that organizes files in a specified directory into subdirectories based on their file types.
Prerequisites
Basic knowledge of Python programming
Understanding of file handling in Python
Familiarity with the os and shutil modules
Resources
Python 3.x
os and shutil modules (pre-installed with Python)
Instructions
1. Setup:
2. Directory Structure:
3. Script Development:
4. Sample Code
import os
import shutil
5. Execution
Save the script as file_organizer.py .
Open a terminal or command prompt.
Navigate to the directory where the script is saved.
Run the script using python file_organizer.py .
2. Email Automation
Objective
Create a Python script that sends automated emails based on specific criteria.
Prerequisites
Basic knowledge of Python programming
Understanding of email protocols (SMTP)
Familiarity with the smtplib and email modules
Resources
Python 3.x
smtplib and email modules (pre-installed with Python)
An email account for sending emails
Instructions
1. Setup:
2. Email Configuration:
3. Script Development:
Create a function to send emails using the smtplib and email modules.
Automate the sending of emails based on certain conditions (e.g., sending reminders).
4. Sample Code:
import smtplib
from email.mime.text import MIMEText
# Example usage
send_email('recipient@example.com', 'Test Subject', 'This is a test email.')
Execution:
Save the script as email_automation.py .
Open a terminal or command prompt.
Navigate to the directory where the script is saved.
Run the script using python email_automation.py .
3. Web Scraper
Objective
Create a Python script that scrapes data from a website and saves it to a file.
Prerequisites
Basic knowledge of Python programming
Understanding of HTML and web scraping techniques
Familiarity with the requests and BeautifulSoup modules
Resources
Python 3.x
requests and BeautifulSoup modules
Install using pip install requests beautifulsoup4
Instructions
1. Setup:
2. Website Selection:
3. Script Development:
4. Sample Code:
import requests
from bs4 import BeautifulSoup
import csv
url = 'https://example.com'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
data = []
for item in soup.find_all('div', class_='item'):
title = item.find('h2').text
price = item.find('span', class_='price').text
data.append([title, price])
Execution:
Save the script as web_scraper.py .
Open a terminal or command prompt.
Navigate to the directory where the script is saved.
Run the script using python web_scraper.py .
4. Expense Tracker
Objective
Create a Python script that tracks your expenses and generates a summary report.
Prerequisites
Basic knowledge of Python programming
Understanding of file handling and CSV operations in Python
Familiarity with the csv module
Resources
Python 3.x
csv module (pre-installed with Python)
Instructions
1. Setup:
Ensure Python is installed on your system.
Open your preferred code editor or IDE.
2. Expense Logging:
Create a function to log expenses.
Store the expenses in a CSV file.
3. Report Generation:
Create a function to read the CSV file and generate a summary report.
4. Script Development:
Implement the logging and reporting functions.
5. Sample Code:
import csv
from datetime import datetime
def generate_report():
with open('expenses.csv', 'r') as file:
reader = csv.reader(file)
total = 0
for row in reader:
total += float(row[1])
print(f'Total Expenses: ${total:.2f}')
# Example usage
log_expense(50, 'Groceries', 'Bought fruits and vegetables')
generate_report()
Execution:
Save the script as expense_tracker.py .
Open a terminal or command prompt.
Navigate to the directory where the script is saved.
Run the script using python expense_tracker.py .
5. Weather App
Objective
Create a Python script that fetches and displays the current weather for a given location.
Prerequisites
Basic knowledge of Python programming
Understanding of API usage and JSON handling in Python
Familiarity with the requests module
Resources
Python 3.x
requests module
Install using pip install requests
Instructions
1. Setup:
Ensure Python is installed on your system.
Open your preferred code editor or IDE.
2. API Configuration:
Sign up for a weather API (e.g., OpenWeatherMap).
Obtain an API key.
3. Script Development:
Use the requests module to fetch weather data from the API.
Parse the JSON response and display the weather information.
4. Sample Code:
import requests
def get_weather(city):
api_key = 'your_api_key'
url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid=
{api_key}&units=metric'
response = requests.get(url)
data = response.json()
if data['cod'] == 200:
weather = data['weather'][0]['description']
temp = data['main']['temp']
print(f'Weather in {city}: {weather}, {temp}°C')
else:
print(f'City {city} not found.')
# Example usage
get_weather('Manila')
Execution:
Save the script as weather_app.py .
Open a terminal or command prompt.
Navigate to the directory where the script is saved.
Run the script using python weather_app.py