10 Powerful Python Automation Scripts to Supercharge Your Workflow
This article presents ten practical Python automation scripts—including image and video optimizers, PDF-to‑image conversion, API data fetching, battery notifications, grammar and spell checkers, internet downloader, world news fetcher, and a PySide2 GUI—each with clear explanations and ready‑to‑run code examples.
Repetitive tasks like cropping hundreds of photos, fetching APIs, or correcting spelling can be time‑consuming; this article shares ten Python automation scripts that streamline such chores.
01. Image Optimizer
Use this handy script to process images automatically, offering Photoshop‑like editing capabilities.
The script relies on the popular Pillow library and provides most methods needed for image optimization.
Use in your image editing projects
Integrate into Python projects
Batch image editing
# Image Optimizing
# pip install Pillow
import PIL
# Cropping
im = PIL.Image.open("Image1.jpg")
im = im.crop((34, 23, 100, 100))
# Resizing
im = PIL.Image.open("Image1.jpg")
im = im.resize((50, 50))
# Flipping
im = PIL.Image.open("Image1.jpg")
im = im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
# Rotating
im = PIL.Image.open("Image1.jpg")
im = im.rotate(360)
# Compressing
im = PIL.Image.open("Image1.jpg")
im.save("Image1.jpg", optimize=True, quality=90)
# Blurring
im = PIL.Image.open("Image1.jpg")
im = im.filter(PIL.ImageFilter.BLUR)
# Sharpening
im = PIL.Image.open("Image1.jpg")
im = im.filter(PIL.ImageFilter.SHARPEN)
# Set Brightness
im = PIL.Image.open("Image1.jpg")
im = PIL.ImageEnhance.Brightness(im)
im = im.enhance(1.5)
# Set Contrast
im = PIL.Image.open("Image1.jpg")
im = PIL.ImageEnhance.Contrast(im)
im = im.enhance(1.5)
# Adding Filters
im = PIL.Image.open("Image1.jpg")
im = PIL.ImageOps.grayscale(im)
im = PIL.ImageOps.invert(im)
im = PIL.ImageOps.posterize(im, 4)
# Saving
im.save("Image1.jpg")02. Video Optimizer
This script uses the MoviePy module to trim, add audio, change speed, apply VFX, and more, enabling full‑featured video automation.
Create a complete video editor
Use in your Python projects
Trim videos
Generate videos from images
# Video Optimizer
# pip install moviepy
import moviepy.editor as pyedit
# Load the Video
video = pyedit.VideoFileClip("vid.mp4")
# Trimming
vid1 = video.subclip(0, 10)
vid2 = video.subclip(20, 40)
final_vid = pyedit.concatenate_videoclips([vid1, vid2])
# Speed up the video
final_vid = final_vid.speedx(2)
# Adding Audio to the video
aud = pyedit.AudioFileClip("bg.mp3")
final_vid = final_vid.set_audio(aud)
# Reverse the Video
final_vid = final_vid.fx(pyedit.vfx.time_mirror)
# Merge two videos
vid1 = pyedit.VideoFileClip("vid1.mp4")
vid2 = pyedit.VideoFileClip("vid2.mp4")
final_vid = pyedit.concatenate_videoclips([vid1, vid2])
# Add VFX to Video
vid1 = final_vid.fx(pyedit.vfx.mirror_x)
vid2 = final_vid.fx(pyedit.vfx.invert_colors)
final_vid = pyedit.concatenate_videoclips([vid1, vid2])
# Add Images to Video
img1 = pyedit.ImageClip("img1.jpg")
img2 = pyedit.ImageClip("img2.jpg")
final_vid = pyedit.concatenate_videoclips([img1, img2])
# Save the video
final_vid.write_videofile("final.mp4")03. PDF to Images
This small script extracts each page of a PDF and saves it as an image using the popular PyMuPDF library.
Use in your PDF projects
Batch convert PDFs to images
# PDF to Images
# pip install PyMuPDF
import fitz
def pdf_to_images(pdf_file):
doc = fitz.open(pdf_file)
for p in doc:
pix = p.get_pixmap()
output = f"page{p.number}.png"
pix.writePNG(output)
pdf_to_images("test.pdf")04. API Data Fetcher
Fetch or post data to APIs using urllib3, providing a quick way to interact with web services.
# pip install urllib3
import urllib3
# Fetch API data
url = "https://api.github.com/users/psf/repos"
http = urllib3.PoolManager()
response = http.request('GET', url)
print(response.status)
print(response.data)
# Post API data
url = "https://httpbin.org/post"
http = urllib3.PoolManager()
response = http.request('POST', url, fields={'hello': 'world'})
print(response.status)05. Battery Notifier
This script monitors battery level with psutil and sends a desktop notification via plyer when the charge drops below a threshold.
# Battery Notifier
# pip install plyer
from plyer import notification
import psutil
from time import sleep
while True:
battery = psutil.sensors_battery()
life = battery.percent
if life < 50:
notification.notify(
title = "Battery Low",
message = "Please connect to power source",
timeout = 10
)
sleep(60)06. Grammar Fixer
Leverage the HappyTransformer library (a machine‑learning model) to automatically correct grammatical errors in text.
# Grammar Fixer
# pip install happytransformer
from happytransformer import HappyTextToText as HappyTTT
from happytransformer import TTSettings
def Grammar_Fixer(Text):
Grammar = HappyTTT("T5", "prithivida/grammar_error_correcter_v1")
config = TTSettings(do_sample=True, top_k=10, max_length=100)
corrected = Grammar.generate_text(Text, args=config)
print("Corrected Text: ", corrected.text)
Text = "This smple tet we how know this"
Grammar_Fixer(Text)07. Spell Fixer
This script uses TextBlob to detect and correct misspelled words in a paragraph or single word.
# Spell Fixer
# pip install textblob
from textblob import *
# Fixing Paragraph Spells
def fix_paragraph_words(paragraph):
sentence = TextBlob(paragraph)
correction = sentence.correct()
print(correction)
# Fixing Word Spells
def fix_word_spell(word):
word = Word(word)
correction = word.correct()
print(correction)
fix_paragraph_words("This is sammple tet!!")
fix_word_spell("maangoo")08. Internet Downloader
Create a custom downloader with the internetdownloadmanager module, capable of downloading images, videos, music, or entire Google Photo albums.
Download Google Photos
Use in your projects
Download videos and music
# Python Downloader
# pip install internetdownloadmanager
import internetdownloadmanager as idm
def Downloader(url, output):
pydownloader = idm.Downloader(worker=20,
part_size=1024*1024*10,
resumable=True,)
pydownloader.download(url, output)
Downloader("Link url", "image.jpg")
Downloader("Link url", "video.mp4")09. World News Fetcher
Fetch up to 50 daily news articles from any country using a free news API.
# World News Fetcher
# pip install requests
import requests
ApiKey = "YOUR_API_KEY"
url = f"https://api.worldnewsapi.com/search-news?text=hurricane&api-key={ApiKey}"
headers = {
'Accept': 'application/json'
}
response = requests.get(url, headers=headers)
print("News: ", response.json())10. PySide2 GUI
This script demonstrates building a simple GUI application with PySide2, showcasing widgets such as buttons, labels, input boxes, radio buttons, checkboxes, sliders, progress bars, images, and message boxes.
# PySide 2
# pip install PySide2
from PySide6.QtWidgets import *
from PySide6.QtGui import *
import sys
app = QApplication(sys.argv)
window = QWidget()
window.resize(500, 500)
window.setWindowTitle("PySide2 Window")
button = QPushButton("Click Me", window)
button.move(200, 200)
label = QLabel("Hello Medium", window)
label.move(200, 150)
input_box = QLineEdit(window)
input_box.move(200, 250)
print(input_box.text())
radio_button = QRadioButton("Radio Button", window)
radio_button.move(200, 300)
checkbox = QCheckBox("Checkbox", window)
checkbox.move(200, 350)
slider = QSlider(window)
slider.move(200, 400)
progress_bar = QProgressBar(window)
progress_bar.move(200, 450)
image = QLabel(window)
image.setPixmap(QPixmap("image.png"))
msg = QMessageBox(window)
msg.setText("Message Box")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
window.show()
sys.exit(app.exec())Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
