Table of Contents
1. Parse and extract HTML
2. QR code scanner
3. Screenshots
4. Create Audiobooks
5. PDF Editor
6. Mini Stackoverflow
7. Automate your phone
8. Monitor CPU/GPU Temperature
9. Instagram Upload Bot
10. Video Watermark
Final Thoughts
Home Backend Development Python Tutorial Ten Python scripts to automate your daily tasks

Ten Python scripts to automate your daily tasks

Apr 12, 2023 pm 01:31 PM
python Script

Ten Python scripts to automate your daily tasks

In this era of automation, we have a lot of repetitive and boring tasks to do. Think of these boring things you no longer have to do over and over again, automate them and make your life easier. Well in this article, I will introduce you to 10 Python automation scripts to make your work more automated and your life easier. So, no more repetitive tasks put this article on your list and let’s get started.

1. Parse and extract HTML

This automated script will help you extract HTML from web page URLs, and then also provide you with tools that can be used to parse the HTML to get the data. Function. This awesome script is a great treat for web crawlers and those who want to parse HTML to get important data.

# 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
Copy after login

2. QR code scanner

If you have a large number of QR code images or just want to scan QR code images, then this automated script will help you. This script uses the Qrtools module, which enables you to scan QR images programmatically.

# 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"))
Copy after login

3. Screenshots

Now you can take screenshots programmatically using this awesome script below. Using this script you can take a screenshot directly or take a screenshot of a specific area.

# Grab Screenshot
# pip install pyautogui
# pip install Pillow
from pyautogui import screenshot
import time
from PIL import ImageGrab
# Grab Screenshot of Screen
def grab_screenshot():
shot = screenshot()
shot.save('my_screenshot.png')
# Grab Screenshot of Specific Area
def grab_screenshot_area():
area = (0, 0, 500, 500)
shot = ImageGrab.grab(area)
shot.save('my_screenshot_area.png')
# Grab Screenshot with Delay
def grab_screenshot_delay():
time.sleep(5)
shot = screenshot()
shot.save('my_screenshot_delay.png')
Copy after login

4. Create Audiobooks

Tired of manually converting your PDF books to audiobooks, then here is your automated script that uses GTTS module to convert your PDF text to Audio.

# 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')
Copy after login

5. PDF Editor

Use the following automated script to edit PDF files using Python. This script uses the PyPDF4 module, which is an upgraded version of PyPDF2. Below I have written common functions such as Parse Text and Remove pages.

This is a handy script when you have a lot of PDF files to edit or need to use the script programmatically in a Python project.

# PDF Editor
# pip install PyPDf4
import PyPDF4
# Parse the Text from PDF
def parse_text(pdf_file):
reader = PyPDF4.PdfFileReader(pdf_file)
for page in reader.pages:
print(page.extractText())
# Remove Page from PDF
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)
# Add Blank Page to PDF
def add_page(pdf_file, page_number):
reader = PyPDF4.PdfFileReader(pdf_file)
writer = PyPDF4.PdfWriter()
writer.addPage()
with open('add.pdf', 'wb') as f:
writer.write(f)
# Rotate Pages
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)
# Merge PDFs
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)
Copy after login

6. Mini Stackoverflow

As a programmer, I know we need StackOverflow every day, but you no longer need to search for it on Google. Now get the solution directly in your CMD while you continue working on your project. By using the Howdoi module, you can get StackOverflow solutions in the command prompt or terminal. Below you can find some examples to try.

# Automate Stackoverflow
# pip install howdoi
# Get Answers in CMD
#example 1
> howdoi how do i install python3
# example 2
> howdoi selenium Enter keys
# example 3
> howdoi how to install modules
# example 4
> howdoi Parse html with python
# example 5
> howdoi int not iterable error
# example 6
> howdoi how to parse pdf with python
# example 7
> howdoi Sort list in python
# example 8
> howdoi merge two lists in python
# example 9
>howdoi get last element in list python
# example 10
> howdoi fast way to sort list
Copy after login

7. Automate your phone

This automation script will help you automate your smartphone using Android Debug Bridge (ADB) in Python. Below I'll show you how to automate common tasks like swipe gestures, calling, sending text messages, and more.

You can learn more about ADB and explore more exciting ways to automate your phone and make your life easier.

# 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')
# Swipe
def swipe(x1, y1, x2, y2, duration):
cmd = 'adb shell input swipe {} {} {} {} {}'.format(x1, y1, x2, y2, duration)
return main_adb(cmd)
# Tap or Clicking
def tap(x, y):
cmd = 'adb shell input tap {} {}'.format(x, y)
return main_adb(cmd)
# Make a Call
def make_call(number):
cmd = f"adb shell am start -a android.intent.action.CALL -d tel:{number}"
return main_adb(cmd)
# Send SMS
def send_sms(number, message):
cmd = 'adb shell am start -a android.intent.action.SENDTO -dsms:{} --es sms_body "{}"'.format(number, message)
return main_adb(cmd)
# Download File From Mobile to PC
def download_file(file_name):
cmd = 'adb pull /sdcard/{}'.format(file_name)
return main_adb(cmd)
# Take a screenshot
def screenshot():
cmd = 'adb shell screencap -p'
return main_adb(cmd)
# Power On and Off
def power_off():
cmd = '"adb shell input keyevent 26"'
return main_adb(cmd)
Copy after login

8. Monitor CPU/GPU Temperature

You may use CPU-Z or any spec monitoring software to capture your Cpu and Gpu temperatures, but you can also do it programmatically. Well, this script uses Pythonnet and OpenhardwareMonitor to help you monitor the current Cpu and Gpu temperatures.

You can use it to notify yourself when a certain temperature is reached, or you can use it in Python projects to simplify your daily life.

# 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()
# Get CPU Temp
def Cpu_Temp():
while True:
for cpu in range(0, len(spec.Hardware[0].Sensors)):
if "/temperature" in str(spec.Hardware[0].Sensors[cpu].Identifier):

print(str(spec.Hardware[0].Sensors[cpu].Value))

# Get GPU Temp
def Gpu_Temp()
while True:
for gpu in range(0, len(spec.Hardware[0].Sensors)):
if "/temperature" in str(spec.Hardware[0].Sensors[gpu].Identifier):
print(str(spec.Hardware[0].Sensors[gpu].Value))
Copy after login

9. Instagram Upload Bot

Instagram is a famous social media platform where you don’t need to upload photos or videos through your smartphone now. You can do this programmatically using the following script.

# Upload Photos and Video on Insta
# pip install instabot
from instabot import Bot
def Upload_Photo(img):
robot = Bot()
robot.login(username="user", password="pass")
robot.upload_photo(img, caption="Medium Article")
print("Photo Uploaded")
def Upload_Video(video):
robot = Bot()
robot.login(username="user", password="pass")
robot.upload_video(video, caption="Medium Article")
print("Video Uploaded")
def Upload_Story(img):
robot = Bot()
robot.login(username="user", password="pass")
robot.upload_story(img, caption="Medium Article")
print("Story Photos Uploaded")
Upload_Photo("img.jpg")
Upload_Video("video.mp4")
Copy after login

10. Video Watermark

Add a watermark to your videos using this automated script that uses Moviepy, a convenient video editing module. In the script below you can see how to add a watermark and use it freely.

# 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')
Copy after login

Final Thoughts

Hope you find some new and interesting things to automate your daily tasks. If you like this article, please don’t forget to share it with your friends. Please also like me and follow me. If you have any questions, please leave me a message in the message area. Thank you for reading and wish you a happy life!

The above is the detailed content of Ten Python scripts to automate your daily tasks. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is there a mobile app that can convert XML into PDF? Is there a mobile app that can convert XML into PDF? Apr 02, 2025 pm 09:45 PM

There is no APP that can convert all XML files into PDFs because the XML structure is flexible and diverse. The core of XML to PDF is to convert the data structure into a page layout, which requires parsing XML and generating PDF. Common methods include parsing XML using Python libraries such as ElementTree and generating PDFs using ReportLab library. For complex XML, it may be necessary to use XSLT transformation structures. When optimizing performance, consider using multithreaded or multiprocesses and select the appropriate library.

Is there any mobile app that can convert XML into PDF? Is there any mobile app that can convert XML into PDF? Apr 02, 2025 pm 08:54 PM

An application that converts XML directly to PDF cannot be found because they are two fundamentally different formats. XML is used to store data, while PDF is used to display documents. To complete the transformation, you can use programming languages ​​and libraries such as Python and ReportLab to parse XML data and generate PDF documents.

How to open xml format How to open xml format Apr 02, 2025 pm 09:00 PM

Use most text editors to open XML files; if you need a more intuitive tree display, you can use an XML editor, such as Oxygen XML Editor or XMLSpy; if you process XML data in a program, you need to use a programming language (such as Python) and XML libraries (such as xml.etree.ElementTree) to parse.

How to beautify the XML format How to beautify the XML format Apr 02, 2025 pm 09:57 PM

XML beautification is essentially improving its readability, including reasonable indentation, line breaks and tag organization. The principle is to traverse the XML tree, add indentation according to the level, and handle empty tags and tags containing text. Python's xml.etree.ElementTree library provides a convenient pretty_xml() function that can implement the above beautification process.

Is the conversion speed fast when converting XML to PDF on mobile phone? Is the conversion speed fast when converting XML to PDF on mobile phone? Apr 02, 2025 pm 10:09 PM

The speed of mobile XML to PDF depends on the following factors: the complexity of XML structure. Mobile hardware configuration conversion method (library, algorithm) code quality optimization methods (select efficient libraries, optimize algorithms, cache data, and utilize multi-threading). Overall, there is no absolute answer and it needs to be optimized according to the specific situation.

How to convert XML files to PDF on your phone? How to convert XML files to PDF on your phone? Apr 02, 2025 pm 10:12 PM

It is impossible to complete XML to PDF conversion directly on your phone with a single application. It is necessary to use cloud services, which can be achieved through two steps: 1. Convert XML to PDF in the cloud, 2. Access or download the converted PDF file on the mobile phone.

How to convert xml into pictures How to convert xml into pictures Apr 03, 2025 am 07:39 AM

XML can be converted to images by using an XSLT converter or image library. XSLT Converter: Use an XSLT processor and stylesheet to convert XML to images. Image Library: Use libraries such as PIL or ImageMagick to create images from XML data, such as drawing shapes and text.

How to control the size of XML converted to images? How to control the size of XML converted to images? Apr 02, 2025 pm 07:24 PM

To generate images through XML, you need to use graph libraries (such as Pillow and JFreeChart) as bridges to generate images based on metadata (size, color) in XML. The key to controlling the size of the image is to adjust the values ​​of the <width> and <height> tags in XML. However, in practical applications, the complexity of XML structure, the fineness of graph drawing, the speed of image generation and memory consumption, and the selection of image formats all have an impact on the generated image size. Therefore, it is necessary to have a deep understanding of XML structure, proficient in the graphics library, and consider factors such as optimization algorithms and image format selection.

See all articles