Chapter 11: Python Programming for Ten Different Applications in Day-to-Day Life


Introduction

Python has emerged as one of the most versatile and beginner-friendly programming languages, enabling professionals and hobbyists alike to automate, solve, and simplify many everyday problems. In this chapter, we explore ten practical applications of Python that impact our daily lives—ranging from automation to entertainment.


1. Email Automation

Application: Sending reminders, newsletters, or bulk emails.

Example Code:

import smtplib
from email.message import EmailMessage

def send_email(to, subject, content):
    msg = EmailMessage()
    msg.set_content(content)
    msg['Subject'] = subject
    msg['From'] = 'youremail@example.com'
    msg['To'] = to

    with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
        smtp.login('youremail@example.com', 'yourpassword')
        smtp.send_message(msg)

send_email("friend@example.com", "Reminder", "Don't forget our meeting at 5 PM!")

2. Daily To-Do List Management

Application: Automating task logging and retrieval.

Example Code:

import datetime

def add_task(task):
    with open("tasks.txt", "a") as file:
        file.write(f"{datetime.date.today()} - {task}\n")

def view_tasks():
    with open("tasks.txt", "r") as file:
        print(file.read())

add_task("Buy groceries")
view_tasks()

3. Expense Tracker

Application: Personal finance tracking.

Example Code:

import csv

def log_expense(item, amount):
    with open('expenses.csv', mode='a', newline='') as file:
        writer = csv.writer(file)
        writer.writerow([item, amount])

def view_expenses():
    with open('expenses.csv', mode='r') as file:
        reader = csv.reader(file)
        for row in reader:
            print(row)

log_expense("Coffee", 3.5)
view_expenses()

4. Weather Updates

Application: Fetching live weather updates.

Example Code:

import requests

def get_weather(city):
    api_key = "your_api_key"
    url = f"http://api.weatherapi.com/v1/current.json?key={api_key}&q={city}"
    response = requests.get(url)
    data = response.json()
    print(f"Weather in {city}: {data['current']['temp_c']}°C, {data['current']['condition']['text']}")

get_weather("New York")

5. Alarm Clock

Application: Daily wake-up alarm.

Example Code:

import time
import os

def set_alarm(alarm_time):
    while True:
        if time.strftime('%H:%M') == alarm_time:
            print("Wake up!")
            os.system("start alarm.mp3")  # Replace with your alarm file
            break
        time.sleep(30)

set_alarm("06:30")

6. File Organizer

Application: Sorting downloads or documents into folders.

Example Code:

import os
import shutil

def organize_files(folder_path):
    for file in os.listdir(folder_path):
        ext = file.split('.')[-1]
        dest_folder = os.path.join(folder_path, ext)
        if not os.path.exists(dest_folder):
            os.makedirs(dest_folder)
        shutil.move(os.path.join(folder_path, file), os.path.join(dest_folder, file))

organize_files("C:/Users/YourUser/Downloads")

7. PDF Merger

Application: Combining multiple PDFs into one.

Example Code:

from PyPDF2 import PdfMerger

def merge_pdfs(files, output):
    merger = PdfMerger()
    for pdf in files:
        merger.append(pdf)
    merger.write(output)
    merger.close()

merge_pdfs(["file1.pdf", "file2.pdf"], "combined.pdf")

8. QR Code Generator

Application: Creating QR codes for websites, Wi-Fi access, or business cards.

Example Code:

import qrcode

def generate_qr(data, filename):
    qr = qrcode.make(data)
    qr.save(filename)

generate_qr("https://www.example.com", "website_qr.png")

9. Instagram Bot

Application: Auto-like or follow using automation (for learning only).

Example Code:

from instabot import Bot

bot = Bot()
bot.login(username="your_username", password="your_password")
bot.follow("example_user")
bot.like_user("example_user", amount=2)

10. Personal Diary App

Application: Digital note-taking with timestamps.

Example Code:

def write_diary(entry):
    with open("diary.txt", "a") as file:
        timestamp = datetime.datetime.now()
        file.write(f"{timestamp}\n{entry}\n\n")

write_diary("Today was a productive day. Finished writing code!")

Conclusion

Python simplifies many mundane tasks through its vast libraries and easy syntax. Whether you're managing finances, automating chores, or working on hobby projects, Python is a handy companion in everyday digital life. The examples in this chapter are just the tip of the iceberg—users are encouraged to experiment and explore more use cases tailored to their needs.


Exercises

  1. Modify the to-do list script to delete tasks after completion.

  2. Enhance the expense tracker to calculate the total monthly expenditure.

  3. Add functionality to the alarm clock to snooze for 5 minutes.

  4. Create a program that sends daily weather updates by email.

  5. Build a GUI-based version of the personal diary app using Tkinter.

Comments