Skip to main content

10 Python Scripts to Automate Your Daily Tasks

·1017 words·5 mins
Python Automation Productivity
Table of Contents

In this age of automation, we often find ourselves performing repetitive and tedious tasks. Imagine not having to do the same boring things over and over again—let’s automate them!
In this article, you’ll find 10 Python scripts to help automate everyday tasks, saving time and making your life easier. Bookmark this guide and start automating your workflow today.


1. Parse and Extract HTML
#

This script helps you extract HTML from a webpage URL and parse it to obtain data. It’s especially useful for web scrapers and developers who need to analyze or extract structured data from HTML pages.

# Parse and Extract HTML
# pip install gazpacho

import gazpacho

# Extract HTML from URL
url = 'https://www.example.com/'
html = gazpacho.get(url)
print(html)

# Extract HTML with Headers
headers = {'User-Agent': 'Mozilla/5.0'}
html = gazpacho.get(url, headers=headers)
print(html)

# Parse HTML
parse = gazpacho.Soup(html)

# Find single tags
tag1 = parse.find('h1')
tag2 = parse.find('span')

# Find multiple tags
tags1 = parse.find_all('p')
tags2 = parse.find_all('a')

# Find tags by class
tag = parse.find('.class')

# Find tags by Attribute
tag = parse.find("div", attrs={"class": "test"})

# Extract text from tags
text = parse.find('h1').text
text = parse.find_all('p')[0].text

2. QR Code Scanner
#

Scan a QR code image programmatically using Python. This script uses the Qrtools module to decode and extract QR data efficiently.

# Qrcode Scanner
# pip install qrtools

from qrtools import Qr
def Scan_Qr(qr_img):
    qr = Qr()
    qr.decode(qr_img)
    print(qr.data)
    return qr.data
    
print("Your Qr Code is: ", Scan_Qr("qr.png"))

3. Take a Screenshot
#

Capture screenshots of your entire screen or a specific region using PyAutoGUI and Pillow. You can also introduce a delay before capturing.

# Grab Screenshot
# pip install pyautogui
# pip install Pillow

from pyautogui import screenshot
import time
from PIL import ImageGrab

def grab_screenshot():
    shot = screenshot()
    shot.save('my_screenshot.png')

def grab_screenshot_area():
    area = (0, 0, 500, 500)
    shot = ImageGrab.grab(area)
    shot.save('my_screenshot_area.png')

def grab_screenshot_delay():
    time.sleep(5)
    shot = screenshot()
    shot.save('my_screenshot_delay.png')

4. Create Audiobooks
#

Convert PDF books into audiobooks with GTTS (Google Text-to-Speech). It reads each page and converts it into an MP3 file.

# Create Audiobooks
# pip install gTTS
# pip install PyPDF2

from PyPDF2 import PdfFileReader as reader
from gtts import gTTS

def create_audio(pdf_file):
    read_Pdf = reader(open(pdf_file, 'rb'))
    for page in range(read_Pdf.numPages):
        text = read_Pdf.getPage(page).extractText()
        tts = gTTS(text, lang='en')
        tts.save('page' + str(page) + '.mp3')
        
create_audio('book.pdf')

5. PDF Editor
#

Edit PDF files using PyPDF4, an enhanced version of PyPDF2. The script provides functions to parse, remove, rotate, and merge PDF pages.

# PDF Editor
# pip install PyPDf4

import PyPDF4

def parse_text(pdf_file):
    reader = PyPDF4.PdfFileReader(pdf_file)
    for page in reader.pages:
        print(page.extractText())

def remove_page(pdf_file, page_numbers):
    filer = PyPDF4.PdfReader('source.pdf', 'rb')
    out = PyPDF4.PdfWriter()
    for index in page_numbers:
        page = filer.pages[index]
        out.add_page(page)
    with open('rm.pdf', 'wb') as f:
        out.write(f)

def add_page(pdf_file):
    reader = PyPDF4.PdfFileReader(pdf_file)
    writer = PyPDF4.PdfWriter()
    writer.addBlankPage()
    with open('add.pdf', 'wb') as f:
        writer.write(f)

def rotate_page(pdf_file):
    reader = PyPDF4.PdfFileReader(pdf_file)
    writer = PyPDF4.PdfWriter()
    for page in reader.pages:
        page.rotateClockwise(90)
        writer.addPage(page)
    with open('rotate.pdf', 'wb') as f:
        writer.write(f)

def merge_pdfs(pdf_file1, pdf_file2):
    pdf1 = PyPDF4.PdfFileReader(pdf_file1)
    pdf2 = PyPDF4.PdfFileReader(pdf_file2)
    writer = PyPDF4.PdfWriter()
    for page in pdf1.pages:
        writer.addPage(page)
    for page in pdf2.pages:
        writer.addPage(page)
    with open('merge.pdf', 'wb') as f:
        writer.write(f)

6. Mini Stack Overflow in Your Terminal
#

Access Stack Overflow answers directly in your terminal with Howdoi. This tool fetches the top-voted answer to your programming question without opening a browser.

# Automate Stack Overflow
# pip install howdoi

# Examples
howdoi how do i install python3
howdoi selenium Enter keys
howdoi Parse html with python
howdoi merge two lists in python
howdoi sort list in python

7. Automate Your Mobile Phone
#

Automate Android phones using ADB (Android Debug Bridge). You can make calls, send texts, take screenshots, or perform gestures—all programmatically.

# Automate Mobile Phones
# pip install opencv-python

import subprocess

def main_adb(cm):
    p = subprocess.Popen(cm.split(' '), stdout=subprocess.PIPE, shell=True)
    (output, _) = p.communicate()
    return output.decode('utf-8')

def swipe(x1, y1, x2, y2, duration):
    cmd = f'adb shell input swipe {x1} {y1} {x2} {y2} {duration}'
    return main_adb(cmd)

def tap(x, y):
    cmd = f'adb shell input tap {x} {y}'
    return main_adb(cmd)

def make_call(number):
    cmd = f"adb shell am start -a android.intent.action.CALL -d tel:{number}"
    return main_adb(cmd)

def send_sms(number, message):
    cmd = f'adb shell am start -a android.intent.action.SENDTO -d sms:{number} --es sms_body "{message}"'
    return main_adb(cmd)

def download_file(file_name):
    cmd = f'adb pull /sdcard/{file_name}'
    return main_adb(cmd)

def screenshot():
    cmd = 'adb shell screencap -p'
    return main_adb(cmd)

def power_off():
    cmd = 'adb shell input keyevent 26'
    return main_adb(cmd)

8. Monitor CPU and GPU Temperature
#

Monitor your system temperature programmatically using Pythonnet and OpenHardwareMonitor. You can use it to trigger alerts when certain temperature thresholds are exceeded.

# Get CPU/GPU Temperature
# pip install pythonnet

import clr
clr.AddReference("OpenHardwareMonitorLib")
from OpenHardwareMonitorLib import *

spec = Computer()
spec.GPUEnabled = True
spec.CPUEnabled = True
spec.Open()

def Cpu_Temp():
    while True:
        for cpu in spec.Hardware[0].Sensors:
            if "/temperature" in str(cpu.Identifier):
                print(cpu.Value)

def Gpu_Temp():
    while True:
        for gpu in spec.Hardware[0].Sensors:
            if "/temperature" in str(gpu.Identifier):
                print(gpu.Value)

9. Instagram Upload Bot
#

Automate photo, video, or story uploads to Instagram using Instabot. This is perfect for content creators or marketers who want to schedule or batch-upload content.

# Upload Photos and Videos on Instagram
# pip install instabot

from instabot import Bot

def Upload_Photo(img):
    bot = Bot()
    bot.login(user)
    bot.upload_photo(img, caption="Automated Upload")

def Upload_Video(video):
    bot = Bot()
    bot.login(user)
    bot.upload_video(video, caption="Automated Upload")

def Upload_Story(img):
    bot = Bot()
    bot.login(user)
    bot.upload_story(img, caption="Automated Story")

Upload_Photo("img.jpg")
Upload_Video("video.mp4")

10. Add a Watermark to Your Videos
#

Easily add text watermarks to videos using MoviePy. Customize fonts, colors, and opacity to match your style.

# Video Watermark with Python
# pip install moviepy

from moviepy.editor import *

clip = VideoFileClip("myvideo.mp4", audio=True)
width, height = clip.size

text = TextClip("WaterMark", font='Arial', color='white', fontsize=28)
set_color = text.on_color(size=(clip.w + text.w, text.h-10),
                          color=(0,0,0), pos=(6,'center'), col_opacity=0.6)
set_textPos = set_color.set_pos(lambda pos: (max(width/30,int(width-0.5*width*pos)),
                                             max(5*height/6,int(100*pos))))

Output = CompositeVideoClip([clip, set_textPos])
Output.duration = clip.duration
Output.write_videofile("output.mp4", fps=30, codec='libx264')

Final Thoughts
#

These 10 scripts show just how powerful Python can be for everyday automation. Whether it’s managing files, editing PDFs, controlling your phone, or adding AI to your workflow—Python makes automation accessible to everyone.

Start small, adapt these scripts to your workflow, and let Python handle the boring stuff while you focus on what matters most.