Operations 13 min read

10 Handy Python Scripts to Automate Everyday Tasks

This article presents ten practical Python scripts that automate common everyday tasks—from CSV parsing and file compression to QR code sharing, keyboard/mouse control, web status checking, GUI creation, TikTok downloading, and HTML requests—helping readers boost productivity with ready‑to‑run code examples.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
10 Handy Python Scripts to Automate Everyday Tasks

In daily life we often perform repetitive tasks such as parsing CSV files, fetching news, editing photos, or sending emails. Automating these with Python can greatly simplify work.

This article shares ten Python scripts for everyday automation, encouraging readers to bookmark the article.

1. Parse CSV

Using Python's built‑in csv module you can read and write CSV files without external dependencies. This lightweight solution is handy when handling multiple CSV files.

# Parse CSV
import csv
def Parse_CSV(filename):
    with open(filename, 'rb') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in reader:
            print(', '.join(row))
def Write_CSV():
    with open('test.csv', 'wb') as csvfile:
        w = csv.writer(csvfile, delimiter=',')
        w.writerow(['Name', 'Age'])
        w.writerow(['John', '23'])
        w.writerow(['Mary', '22'])
Parse_CSV("test.csv")
Write_CSV()

2. Compress Large Files

This script uses the built‑in zipfile module to compress several files into a single zip archive, reducing their size.

# Compress Large Files
import zipfile as Zip
def Compressor(files):
    zip = Zip.ZipFile("output.zip", "w", Zip.ZIP_DEFLATED)
    for f in files:
        zip.write(f, compress_type=Zip.ZIP_DEFLATED)
    zip.close()
    print("Compressed")
Compressor(["video.mkv", "image.jpg"])

3. Share File via QR Code

The script generates a QR code that links to a file, allowing anyone to download the shared file after scanning.

# Share File QrCode
# pip install share-file-qr
# pip install qrcode
import subprocess as proc
import qrcode
def Share_Files_Qr(file):
    qr = qrcode.QRCode(
        version=1,
        box_size=10,
        border=4,
    )
    qr.add_data(f"http://192.168.0.105:4000/file/{file}")
    qr.make(fit=True)
    qr.make_image().save("qrcode.png")
    proc.call(f"share-file-qr {file}", stderr=proc.STDOUT)
Share_Files_Qr("test.png")

4. Python Photoshop

Using Pillow, this script performs common image‑processing operations such as cropping, resizing, rotating, flipping, compressing, converting to greyscale, enhancing contrast, blurring, adding drop‑shadow, adjusting brightness, and merging images.

# Python Photoshop
# pip install Pillow
from PIL import Image
import PIL
# loading image
im = Image.open("python.png")
# get image info
print(im.format, im.size, im.mode)
# Crop
img = im.crop((0, 0, 100, 100))
img.save("cropped.png")
# Resize
img = im.resize((100, 100), Image.ANTIALIAS)
img.save("resized.png")
# Rotate
img = im.rotate(180)
img.save("rotated.png")
# Flip
img = im.transpose(Image.FLIP_LEFT_RIGHT)
img.save("flip.png")
# Compress size
img.save("python.png", optimize=True, quality=95)
# Greyscale
img = im.convert('L')
img.save("grey.png")
# Enhance image
enhancer = PIL.ImageEnhance.Contrast(im)
enhancer.enhance(1.3)
img.save("enhanced_image.png")
# Blur
img = im.filter(PIL.ImageFilter.BLUR)
img.save("bluring.png")
# Drop shadow Effect
img = im.filter(PIL.ImageFilter.GaussianBlur(2))
img.save("drop_shadow.png")
# Increase brightness
img = im.point(lambda b: b * 1.2)
img.save("bright.png")
# merge two images
img2 = Image.open("python2.png")
img = Image.blend(im, img2, 0.5)
img.save("merge.png")

5. Fetch Top Headlines

This script scrapes the NBC News homepage to retrieve headline titles and their URLs, useful for building a news application.

# Fetch Top Headlines
# pip install requests
# pip install bs4
import requests
from bs4 import BeautifulSoup
url = "https://www.nbcnews.com/"
response = requests.get(url)
html = BeautifulSoup(response.text, "html.parser")
for news in html.find_all("h3"):
    print("Headline:", news.text)
    print("Link:", news.find("a")["href"])

6. Control Keyboard and Mouse

Using the mouse and keyboard modules, this script programmatically moves the cursor, clicks buttons, drags, and simulates key presses.

# Control keyboard and Mouse
# pip install mouse
# pip install keyboard
import mouse
import keyboard
# Move mouse cursor
mouse.move(100, 100, duration=0.5)
# Click mouse left btn
mouse.click('left')
# Click mouse right btn
mouse.click('right')
# Click mouse middle btn
mouse.click('middle')
# Drag mouse
mouse.drag(100, 100, duration=0.5)
# get mouse position
mouse.get_position()
# Press keyboard key
keyboard.press('a')
# Release keyboard key
keyboard.release('a')
# Type on keyboard
keyboard.write('Python Coding')
# Press and release keyboard key
keyboard.press_and_release('a')
# Combination of keys
keyboard.add_hotkey('ctrl + shift + a')

7. Web Status Checker

The script uses urllib3 to send an HTTP GET request to a website and prints whether the site is online based on the response status.

# Web Status Checker
# pip install urllib3
import urllib3
import time
web = "https://www.medium.com"
http = urllib3.PoolManager()
response = http.request('GET', web)
if response.status == 200:
    print("Web is online")
else:
    print("Web is offline")

8. Tkinter GUI

This example creates a simple graphical user interface with Tkinter, adding labels, buttons, input boxes, radio buttons, checkboxes, and an image.

# Tkinter GUI
from tkinter import *
pygui = Tk()
# Set Screen Title
pygui.title("Python GUI APP")
# Set Screen Size
pygui.geometry("1920x1080")
# Set Screen Bg Color
pygui.configure(bg="White")
# Set Screen Icon
pygui.iconbitmap("icon.ico")
# Add Label Text
Text = Label(pygui, text="Medium", font=("Arial", 50))
Text.place(x=100, y=100)
# Add Buttons
btn = Button(pygui, text="Hi! Click Me", font=("Arial", 20))
btn.place(x=100, y=200)
# Add Input Box
var = StringVar()
input = Entry(pygui, textvariable=var, font=("Arial", 20))
input.place(x=100, y=300)
# Add Text Box
text = Text(pygui, width=50, height=10)
text.place(x=100, y=400)
# Add Radio btns
var = IntVar()
radio1 = Radiobutton(pygui, text="Option 1", variable=var, value=1)
radio1.place(x=100, y=500)
# Add Checkboxes
var = IntVar()
check = Checkbutton(pygui, text="Check Me", variable=var)
check.place(x=100, y=600)
# Add Image
img = PhotoImage(file="image.png")
image = Label(pygui, image=img)
image.place(x=100, y=600)
# loop
pygui.mainloop()

9. TikTok Video Downloader

By combining Selenium, webdriver‑manager, and BeautifulSoup, this script runs headlessly to download a TikTok video given its URL.

# Tiktok Video Downloader
# pip install selenium
# pip install webdriver-manager
# pip install beautifulsoup4
from selenium import webdriver as web
from webdriver_manager.chrome import *
import time
from bs4 import BeautifulSoup as bs
import urllib.request
def tiktok_downloader(url):
    op = web.ChromeOptions()
    op.add_argument('--headless')
    driver = web.Chrome(ChromeDriverManager().install(), options=op)
    driver.get(url)
    time.sleep(5)
    html = driver.page_source
    soup = bs(html, 'html.parser')
    video = soup.find('video')
    urllib.request.urlretrieve(video['src'], 'video.mp4')
tiktok_downloader("https://www.tiktok.com/video/xxxx")

10. Request HTML

This script uses requests_html to render JavaScript‑loaded pages and print the status code and HTML content.

# Request HTML
# pip install requests_html
from requests_html import HTMLSession
url = 'https://www.google.com/search?q=python'
session = HTMLSession()
req = session.get(url, timeout=20)
req.html.render(sleep=1)
print(req.status_code)
print(req.html.html)

These Python automation scripts demonstrate how the language can streamline routine tasks, improve efficiency, and serve as a versatile tool for developers and hobbyists alike.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

productivityexamplesscripts
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.