Operations 8 min read

Six Python Automation Scripts for Common Repetitive Tasks

This article presents six practical Python scripts that automate repetitive tasks such as image processing, video editing, PDF‑to‑image conversion, API interaction, file downloading, and fetching world news, providing ready‑to‑run code examples for each use case.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Six Python Automation Scripts for Common Repetitive Tasks

Repetitive tasks like cropping hundreds of photos, editing videos, or downloading many files can be time‑consuming, so automating them with Python scripts can save effort.

01. Image Processor

This script uses the Pillow library to perform common image operations such as cropping, resizing, flipping, rotating, compressing, blurring, sharpening, adjusting brightness and contrast, applying filters, and saving the result.

# Image Optimizing
# pip install Pillow
import PIL
# Cropping
im = PIL.Image.open("Image1.jpg")
im = im.crop((34, 23, 100, 100))
# Resizing
im = im.resize((50, 50))
# Flipping
im = im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
# Rotating
im = im.rotate(360)
# Compressing
im.save("Image1.jpg", optimize=True, quality=90)
# Blurring
im = im.filter(PIL.ImageFilter.BLUR)
# Sharpening
im = im.filter(PIL.ImageFilter.SHARPEN)
# Set Brightness
im = PIL.ImageEnhance.Brightness(im).enhance(1.5)
# Set Contrast
im = PIL.ImageEnhance.Contrast(im).enhance(1.5)
# Adding Filters
im = PIL.ImageOps.grayscale(im)
im = PIL.ImageOps.invert(im)
im = PIL.ImageOps.posterize(im, 4)
# Saving
im.save("Image1.jpg")

02. Video Cutter

Using the MoviePy library, this script can trim video clips, change playback speed, add audio, reverse video, merge clips, apply visual effects, insert images, and finally export the edited video.

# Video Optimizer
# pip install moviepy
import moviepy.editor as pyedit
video = pyedit.VideoFileClip("vid.mp4")
vid1 = video.subclip(0, 10)
vid2 = video.subclip(20, 40)
final_vid = pyedit.concatenate_videoclips([vid1, vid2])
final_vid = final_vid.speedx(2)
aud = pyedit.AudioFileClip("bg.mp3")
final_vid = final_vid.set_audio(aud)
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
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])
final_vid.write_videofile("final.mp4")

03. PDF to Images

This script leverages PyMuPDF (fitz) to open a PDF file, iterate through its pages, render each page as a bitmap, and save each page as a PNG image.

# 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

Using urllib3, this script demonstrates how to send GET requests to retrieve data from an API and POST requests to submit data, printing the HTTP status and response body.

# 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"
response = http.request('POST', url, fields={'hello': 'world'})
print(response.status)
print(response.data)

05. Internet Downloader

This script uses the internetdownloadmanager package to create a multi‑threaded downloader capable of resuming interrupted downloads and handling large files.

# 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")

06. World News Fetcher

With the requests library, this script calls a news API (requiring an API key) to retrieve up to 50 recent news articles about a given topic and prints the JSON response.

# 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())

The article concludes with a call‑to‑action encouraging readers to scan a QR code to receive free Python learning resources.

Pythonautomationimage-processingAPIscriptingvideo editing
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

login 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.