Essential Python Scripts for Everyday Tasks

 

Essential Python Scripts for Everyday Tasks



Python is not just for developers—it’s a versatile tool that can make your daily tasks easier, faster, and smarter. 

Whether you’re managing files, automating repetitive tasks, or even simplifying personal chores, Python scripts can save you time and effort.

In this article, i will cover some of the most useful Python scripts you can implement today. 

These scripts are beginner-friendly yet powerful enough to impress even seasoned coders.

1. Organize Files Automatically

Tired of a cluttered downloads folder? Use this script to organize files by type—documents, images, videos, etc.—into their respective folders.

Download this Script

import os

import shutil


folder_path = "/path/to/your/folder"


for filename in os.listdir(folder_path):

    file_ext = filename.split('.')[-1]

    dest_folder = os.path.join(folder_path, file_ext)

    

    if not os.path.exists(dest_folder):

        os.makedirs(dest_folder)

    

    shutil.move(os.path.join(folder_path, filename), os.path.join(dest_folder, filename))

2. Automate Email Sending

Send multiple emails without typing each one manually.

import smtplib

from email.mime.text import MIMEText


def send_email(subject, body, to_email):

    from_email = "your_email@example.com"

    password = "your_password"

    

    msg = MIMEText(body)

    msg["Subject"] = subject

    msg["From"] = from_email

    msg["To"] = to_email

    

    server = smtplib.SMTP("smtp.gmail.com", 587)

    server.starttls()

    server.login(from_email, password)

    server.sendmail(from_email, to_email, msg.as_string())

    server.quit()


send_email("Daily Reminder", "Don't forget to complete your tasks!", "recipient_email@example.com")

3. Web Scraping for Quick Data

Need to extract data from a website? This script gets you started.

import requests

from bs4 import BeautifulSoup


url = "https://example.com"

response = requests.get(url)

soup = BeautifulSoup(response.content, "html.parser")


for item in soup.find_all("h2"):

    print(item.text)

4. Password Generator

Generate strong, random passwords to stay secure online.

import random
import string
def generate_password(length=12):
chars = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(chars) for _ in range(length))
print("Your password:", generate_password())

5. Convert Text to Speech

Turn any text file into an audio file with this simple script.

from gtts import gTTS
text = "Hello! This is your text-to-speech assistant."
tts = gTTS(text)
tts.save("output.mp3")
print("Audio file saved as output.mp3")


6. Monitor System Performance

import psutil

print("CPU Usage:", psutil.cpu_percent(interval=1), "%")
print("Memory Usage:", psutil.virtual_memory().percent, "%")

7. Automate Backups

Automatically back up important files to a designated folder.

import shutil
import os
import time
source_folder = "/path/to/source"
backup_folder = "/path/to/backup"
while True:
shutil.copytree(source_folder, backup_folder, dirs_exist_ok=True)
print("Backup completed.")
time.sleep(86400) # Backup every 24 hours

8. Daily Weather Updates

Get the day’s weather directly from the command line.

import requests
city = "London"
api_key = "your_openweathermap_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()
print("Weather:", data["weather"][0]["description"])
print("Temperature:", data["main"]["temp"], "°C")


9. Social Media Automation

Post tweets automatically with this script.

import tweepy
api_key = "your_api_key"
api_secret = "your_api_secret"
access_token = "your_access_token"
access_token_secret = "your_access_token_secret"
auth = tweepy.OAuth1UserHandler(api_key, api_secret, access_token, access_token_secret)
api = tweepy.API(auth)
api.update_status("Hello Twitter! This is a test tweet.")
print("Tweet posted!")


10. Create a To-Do List

A simple script to manage tasks for your day.

tasks = []
while True:
action = input("Add, View, or Quit: ").lower()
if action == "add":
task = input("Enter your task: ")
tasks.append(task)
elif action == "view":
print("\n".join(tasks))
elif action == "quit":
break

Why Python Scripts?

Python scripts are easy to write and execute, even for beginners. These scripts can be tailored to meet your specific needs and simplify your daily routines.

Conclusion

With these essential Python scripts, you can automate mundane tasks and focus on what truly matters. Start implementing them today, and experience how powerful Python can be in your everyday life!


Post a Comment

Previous Post Next Post