Fundamentals 10 min read

13 Advanced Python Scripts for Everyday Tasks

This article presents thirteen advanced Python scripts covering tasks such as internet speed testing, Google searching, web automation, lyric retrieval, EXIF extraction, OCR, image cartoonization, recycle bin cleaning, image enhancement, Windows version detection, PDF-to-image conversion, hex-to-RGB conversion, and website status checking, each with code examples.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
13 Advanced Python Scripts for Everyday Tasks

Every day we face many programming challenges that require advanced coding; simple Python syntax is insufficient. This article shares 13 advanced Python scripts that can serve as handy tools for your projects.

1. Speed Test with Python

This advanced script helps you test your Internet speed using Python. Install the speed‑test modules and run the following code.

# pip install pyspeedtest
# pip install speedtest
# pip install speedtest-cli
# method 1
import speedtest
speedTest = speedtest.Speedtest()
print(speedTest.get_best_server())
# Check download speed
print(speedTest.download())
# Check upload speed
print(speedTest.upload())
# Method 2
import pyspeedtest
st = pyspeedtest.SpeedTest()
st.ping()
st.download()
st.upload()

2. Google Search via Python

You can extract redirected URLs from Google Search by installing the required module and using the code below.

# pip install google
from googlesearch import search
query = "Medium.com"
for url in search(query):
    print(url)

3. Build a Web Robot

This script automates website interactions using Selenium, allowing you to control any site programmatically.

# pip install selenium
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
bot = webdriver.Chrome("chromedriver.exe")
bot.get('http://www.google.com')
search = bot.find_element_by_name('q')
search.send_keys("@codedev101")
search.send_keys(Keys.RETURN)
time.sleep(5)
bot.quit()

4. Retrieve Song Lyrics

Fetch lyrics from any song by obtaining a free API key from LyricsGenius and running the following script.

# pip install lyricsgenius
import lyricsgenius
api_key = "xxxxxxxxxxxxxxxxxxxxx"
genius = lyricsgenius.Genius(api_key)
artist = genius.search_artist("Pop Smoke", max_songs=5, sort="title")
song = artist.song("100k On a Coupe")
print(song.lyrics)

5. Get Photo EXIF Data

Use the Pillow module to extract EXIF metadata from photos. Two methods are provided.

# Get Exif of Photo
# Method 1
# pip install pillow
import PIL.Image
import PIL.ExifTags
img = PIL.Image.open("Img.jpg")
exif_data = {
    PIL.ExifTags.TAGS[i]: j
    for i, j in img._getexif().items()
    if i in PIL.ExifTags.TAGS
}
print(exif_data)
# Method 2
# pip install ExifRead
import exifread
filename = open(path_name, 'rb')
tags = exifread.process_file(filename)
print(tags)

6. OCR Text Extraction from Images

Optical character recognition (OCR) converts scanned images to text. Install Tesseract and run the script below.

# pip install pytesseract
import pytesseract
from PIL import Image
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

t = Image.open("img.png")
text = pytesseract.image_to_string(t, config='')
print(text)

7. Cartoonize a Photo

This script transforms a photo into a cartoon‑style image using OpenCV.

# pip install opencv-python
import cv2

img = cv2.imread('img.jpg')
grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
grayimg = cv2.medianBlur(grayimg, 5)

edges = cv2.Laplacian(grayimg, cv2.CV_8U, ksize=5)
r, mask = cv2.threshold(edges, 100, 255, cv2.THRESH_BINARY_INV)
img2 = cv2.bitwise_and(img, img, mask=mask)
img2 = cv2.medianBlur(img2, 5)

cv2.imwrite('cartooned.jpg', mask)

8. Empty Recycle Bin

This simple script empties the Windows recycle bin using the winshell library.

# pip install winshell
import winshell
try:
    winshell.recycle_bin().empty(confirm=False, /show_progress=False, sound=True)
    print("Recycle bin is emptied Now")
except:
    print("Recycle bin already empty")

9. Python Image Enhancement

Enhance photos with Pillow by applying color, contrast, brightness, and sharpness adjustments.

# pip install pillow
from PIL import Image, ImageFilter, ImageEnhance

im = Image.open('img.jpg')
# Choose your filter
en = ImageEnhance.Color(im)
en = ImageEnhance.Contrast(im)
en = ImageEnhance.Brightness(im)
en = ImageEnhance.Sharpness(im)

en.enhance(1.5).show('enhanced')

10. Get Windows Version

This script retrieves the full Windows OS version using the wmi module.

# Window Version
import wmi
data = wmi.WMI()
for os_name in data.Win32_OperatingSystem():
    print(os_name.Caption)
# Microsoft Windows 11 Home

11. Convert PDF to Images

Convert each page of a PDF into separate image files using PyMuPDF (fitz).

# PDF to Images
import fitz
pdf = 'sample_pdf.pdf'
doc = fitz.open(pdf)

for page in doc:
    pix = page.getPixmap(alpha=False)
    pix.writePNG('page-%i.png' % page.number)

12. Hex to RGB Conversion

Convert hexadecimal color codes to RGB tuples with a simple function.

# Conversion: Hex to RGB
def Hex_to_Rgb(hex):
    h = hex.lstrip('#')
    return tuple(int(h[i:i+2], 16) for i in (0, 2, 4))

print(Hex_to_Rgb('#c96d9d'))  # (201, 109, 157)
print(Hex_to_Rgb('#fa0515'))  # (250, 5, 21)

13. Website Status Check

Check whether a website is up by retrieving its HTTP status code using urllib or requests.

# pip install requests
# method 1
import urllib.request
from urllib.request import Request, urlopen
req = Request('https://medium.com/@pythonians', headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).getcode()
print(webpage)  # 200
# method 2
import requests
r = requests.get("https://medium.com/@pythonians")
print(r.status_code)  # 200

These scripts provide ready‑to‑use solutions for a variety of practical programming tasks.

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.

PythonAutomationImage ProcessingData ExtractionAdvanced Scripts
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.