10 Python Automation Scripts for Killer Applications
01, Image Optimizer
This great automation script can help you process images better, you can just like in Photoshop Edit them.
This script uses the popular Pillow module.
# 图像优化 # pip install Pillow import PIL # 裁剪 im = PIL.Image.open("Image1.jpg") im = im.crop((34, 23, 100, 100)) # 调整大小 im = PIL.Image.open("Image1.jpg") im = im.resize((50, 50)) # 翻转 im = PIL.Image.open("Image1.jpg") im = im.transpose(PIL.Image.FLIP_LEFT_RIGHT) # 旋转 im = PIL.Image.open("Image1.jpg") im = im.rotate(360) # 压缩 im = PIL.Image.open("Image1.jpg") im.save("Image1.jpg", optimize=True, quality=90) # 模糊化 im = PIL.Image.open("Image1.jpg") im = im.filter(PIL.ImageFilter.BLUR) # 锐化 im = PIL.Image.open("Image1.jpg") im = im.filter(PIL.ImageFilter.SHARPEN) # 设置亮度 im = PIL.Image.open("Image1.jpg") im = PIL.ImageEnhance.Brightness(im) im = im.enhance(1.5) # 设置对比度 im = PIL.Image.open("Image1.jpg") im = PIL.ImageEnhance.Contrast(im) im = im.enhance(1.5) # 添加过滤器 im = PIL.Image.open("Image1.jpg") im = PIL.ImageOps.grayscale(im) im = PIL.ImageOps.invert(im) im = PIL.ImageOps. posterize(im, 4) # 保存 im.save("Image1.jpg")
02, Video Optimizer
With the following automated script, you can not only use Python to optimize videos, but also use it to optimize images. This script uses the Moviepy module, which allows you to trim, add audio, set video speed, add VFX, and more.
# 视频优化器 # 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) # 合并两个视频 vid1 = pyedit.VideoFileClip("vid1.mp4") vid2 = pyedit.VideoFileClip("vid2.mp4") final_vid = pyedit.concatenate_videoclips([vid1, vid2]) # 在视频中添加视觉特效 vid1 = final_vid.fx(pyedit.vfx.mirror_x) vid2 = final_vid.fx(pyedit.vfx.invert_colors) final_vid = pyedit.concatenate_videoclips([vid1, vid2]) # 在视频中添加图像 img1 = pyedit.ImageClip("img1.jpg") img2 = pyedit.ImageClip("img2.jpg") final_vid = pyedit.concatenate_videoclips([img1, img2]) # 保存视频 final_vid.write_videofile("final.mp4")
03. Convert PDF to Image
This small automated script can easily retrieve entire PDF pages and convert them to images. This script uses the popular PyMuPDF module, known for its PDF text extraction.
# 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. Get API data
If you need to get API data from the database, or need to send API requests to the server, this automation script is a convenient tool for you. Using the Urlib3 module, you can get and make API requests.
# pip install urllib3 输入urllib3 # 获取API数据 url = "https://api.github.com/users/psf/repos" http = urllib3.PoolManager() response = http.request('GET', url) print(response.status) print(response.data) # 发布API数据 url = "https://httpbin.org/post" http = urllib3.PoolManager() response = http.request('POST', url, fields={'hello': 'world'}) print(response.status)
05, Battery Indicator
This handy script allows you to set the battery percentage at which you want to receive notifications. The script uses Pyler for notifications and Psutil to get the current battery percentage.
# 电池通知器 # pip instal 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 Corrector
Tired of proofreading your long articles or texts? Well, you can try this automatic script that will scan your text and correct grammatical errors. This great script uses the Happtransformer module, which is a machine learning module trained to correct grammatical errors in text.
# Grammer Fixer # pip install happytransformer from happytransformer import HappyTextToText as HappyTTT from happytransformer import TTSettings def Grammer_Fixer(Text): Grammer = HappyTTT("T5","prithivida/grammar_error_correcter_v1") config = TTSettings(do_sample=True, top_k=10, max_length=100) corrected = Grammer.generate_text(Text, args=config) print("Corrected Text: ", corrected.text) Text = "This is smple tet we how know this" Grammer_Fixer(Text)
07. Spelling Correction
This great script will help you correct spelling errors in text words. You can find a script below that will tell you how to fix single or multiple words in a sentence.
# 拼写修正器 # pip 安装 textblob # pip install textblob from textblob import * def fix_paragraph_words(paragraph): sentence = TextBlob(paragraph) correction = sentence.correct() print(correction) # 修复字词拼写 def fix_word_spell(word): word = Word(word) 更正 = word.correct() print(correction) fix_paragraph_words("this is sammple tet!!") fix_word_spell("maangoo")
08, Internet Downloader
You may use downloading software to download photos or videos from the Internet, but now you can create your own downloader using the Python IDM module.
# 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. Get world news
Use this automatic script to update daily world news in any language of any country at any time. This API allows you to get 50 news items per day for free.
# pip install requests import requests ApiKey = "YOUR_API_KEY" url = "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 automated script will help you create your GUI application using the PySide2 Gui module. Below you'll find every method you need to start developing the front-end of a modern application.
# PySide2 # pip install PySide2 from PySide6.QtWidgets import * from PySide6.QtGui import * 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())
The above is the detailed content of Several application scenarios of Python automation scripts. For more information, please follow other related articles on the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software