10 个超级高效实用的 Python 自动化脚本!

这篇具有很好参考价值的文章主要介绍了10 个超级高效实用的 Python 自动化脚本!。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

重复性任务总是耗时且无聊,想一想你想要一张一张地裁剪 100 张照片或 Fetch API、纠正拼写和语法等工作,所有这些任务都很耗时,为什么不自动化它们呢?在今天的文章中,我将与你分享 10 个 Python 自动化脚本。

所以,请你把这篇文章放在你的收藏清单上,以备不时之需。

现在,让我们开始吧。

01、 图片优化器

使用这个很棒的自动化脚本,可以帮助把图像处理的更好,你可以像在 Photoshop 中一样编辑它们。

该脚本使用流行的是 Pillow 模块

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

02、视频优化器

通过使用以下自动化脚本,你不仅可以使用 Python 来优化视频,还可以使用它来优化图像。该脚本使用 Moviepy 模块,允许你修剪、添加音频、设置视频速度、添加 VFX 等等。

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

03、PDF 转图片

这个小型自动化脚本可以方便地获取整个 PDF 页面并将它们转换为图像。该脚本使用流行的 PyMuPDF 模块,该模块以其 PDF 文本提取而闻名。

# 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 数据

需要从数据库中获取 API 数据或需要向服务器发送 API 请求。那么这个自动化脚本对你来说是一个方便的工具。使用 Urllib3 模块,可让你获取和发布 API 请求。

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

05、电池指示灯

这个方便的脚本可以让你设置你想要得到通知的电池百分比,该脚本使用 Pyler 进行通知,使用 Psutil 获取当前的电池百分比。

# Battery Notifier
# 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、语法固定器

厌倦了校对你的长文章或文本,然后,你可以试试这个自动化脚本,它将扫描你的文本并纠正语法错误,这个很棒的脚本使用 Happtransformer 模块,这是一个机器学习模块,经过训练可以修复文本中的语法错误。


# 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、拼写修正

这个很棒的脚本将帮助你纠正你的文本单词拼写错误。你可以在下面找到脚本,将告诉你如何修复句子中的单个单词或多个单词。

# Spell Fixer
# pip install textblob
from textblob import *
# Fixing Paragraph Spells
def fix_paragraph_words(paragraph):
    sentence = TextBlob(paragraph)
    correction = sentence.correct()
    print(correction)
# Fixing Words Spells
def fix_word_spell(word):
    word = Word(word)
    correction = word.correct()
    print(correction)
fix_paragraph_words("This is sammple tet!!")
fix_word_spell("maangoo")

08、互联网下载器

你们可能使用下载软件从 Internet 下载照片或视频,但现在你可以使用 Python IDM 模块创建自己的下载器。

# 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、获取世界新闻

使用此自动化脚本让你随时了解每日世界新闻,你可以使用任何语言从任何国家/地区获取新闻。这个 API 让你每天免费获取 50 篇新闻文章。


# World News Fetcher
# 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

这个自动化脚本将帮助你使用 PySide2 Gui 模块创建你的 GUI 应用程序。你可以在下面找到开始开发体面的现代应用程序所需的每种方法。

# PySide 2 
# pip install PySide2
from PySide6.QtWidgets import *
from PySide6.QtGui import *
import sys
app = QApplication(sys.argv)
window = QWidget()
# Resize the Window
window.resize(500, 500)
# Set the Window Title
window.setWindowTitle("PySide2 Window")
# Add Buttons
button = QPushButton("Click Me", window)
button.move(200, 200)
# Add Label Text
label = QLabel("Hello Medium", window)
label.move(200, 150)
# Add Input Box
input_box = QLineEdit(window)
input_box.move(200, 250)
print(input_box.text())
# Add Radio Buttons
radio_button = QRadioButton("Radio Button", window)
radio_button.move(200, 300)
# Add Checkbox
checkbox = QCheckBox("Checkbox", window)
checkbox.move(200, 350)
# Add Slider
slider = QSlider(window)
slider.move(200, 400)
# Add Progress Bar
progress_bar = QProgressBar(window)
progress_bar.move(200, 450)
# Add Image 
image = QLabel(window)
image.setPixmap(QPixmap("image.png"))
# Add Message Box
msg = QMessageBox(window)
msg.setText("Message Box")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
window.show()
sys.exit(app.exec())
- END -


除上述资料外,还附赠全套Python学习资料,包含面试题、简历资料等具体看下方。

🎁福利🎁 全网最全《Python学习资料》免费赠送🆓!

学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!

python自动化,python,自动化,开发语言
一、Python学习路线

python自动化,python,自动化,开发语言
python自动化,python,自动化,开发语言

二、Python基础学习
1. 开发工具

python自动化,python,自动化,开发语言

2. 学习笔记

python自动化,python,自动化,开发语言

3. 学习视频

python自动化,python,自动化,开发语言

三、Python小白必备手册

python自动化,python,自动化,开发语言

四、数据分析全套资源

python自动化,python,自动化,开发语言

五、Python面试集锦
1. 面试资料

python自动化,python,自动化,开发语言

python自动化,python,自动化,开发语言

2. 简历模板

python自动化,python,自动化,开发语言

python自动化,python,自动化,开发语言

因篇幅有限,仅展示部分资料,添加上方即可获取文章来源地址https://www.toymoban.com/news/detail-719271.html

到了这里,关于10 个超级高效实用的 Python 自动化脚本!的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 10个常用python自动化脚本

    大家好,Python凭借其简单和通用性,能够为解决每天重复同样的工作提供最佳方案。本文将探索10个Python脚本,这些脚本可以帮助自动化完成任务,提高工作效率。无论是开发者、数据分析师还是仅仅想简化工作流程的普通用户,这些脚本都能提供帮助。 1.1 排序目录中的文件

    2024年01月23日
    浏览(38)
  • 10 个杀手级的 Python 自动化脚本

    重复性任务总是耗时且无聊,想一想你想要一张一张地裁剪 100 张照片或 Fetch API、纠正拼写和语法等工作,所有这些任务都很耗时,为什么不自动化它们呢?在今天的文章中,我将与你分享 10 个 Python 自动化脚本。 所以,请你把这篇文章放在你的收藏清单上,以备不时之需,

    2024年02月19日
    浏览(37)
  • 用于自动化的 10 个杀手级 Python 脚本

    用于自动化的 10 个杀手级 Python 脚本 您是否厌倦了在繁琐的任务上浪费时间? 您是否梦想着一个计算机为您完成所有工作的世界?别无所求,因为我们有 5 个 Python 脚本,准备好告别体力劳动,自动化开始吧! “自动化不是人类工人的敌人,而是盟友。自动化将工人从苦差

    2023年04月27日
    浏览(28)
  • 10个Python脚本来自动化你的日常任务

    在这个自动化时代,我们有很多重复无聊的工作要做。想想这些你不再需要一次又一次地做的无聊的事情,让它自动化,让你的生活更轻松。那么在本文中,我将向您介绍 10 个 Python 自动化脚本,以使你的工作更加自动化,生活更加轻松。因此,没有更多的重复任务将这篇文

    2024年01月19日
    浏览(39)
  • Shell脚本入门实战:探索自动化任务与实用场景

    引言 Shell脚本作为一种强大的自动化工具,在现代操作系统中具有广泛的应用。无论是简单的文件操作,还是复杂的系统管理,Shell脚本都能提供高效、快速的解决方案。在本文中,我们将探索Shell脚本的基础知识,并通过实战场景示例,一起深入了解Shell脚本编程。 1. Shell脚

    2024年02月02日
    浏览(39)
  • 云计算的自动化与脚本:实现高效运维

    云计算是一种基于互联网和服务器集群的计算模式,它允许用户在需要时从任何地方访问计算资源。自动化和脚本在云计算中发挥着至关重要的作用,因为它们可以帮助管理员更高效地运行和维护云计算环境。在本文中,我们将探讨云计算自动化和脚本的核心概念、算法原理

    2024年04月12日
    浏览(37)
  • 快速手动完成 VS 编写脚本自动化:如何选取最高效的工作方式?

    那些不懂技术的朋友们可能会觉得,写代码写脚本不就是敲敲键盘嘛,搞那么高科技做什么,直接手工点点鼠标不就完事了。 这种看法很常见,但实际情况要复杂得多。 首先,手工操作虽然对于短期和小规模的任务来说似乎更快,但是它没法保证一致性和准确性,而且重复

    2024年02月20日
    浏览(33)
  • [Python自动化]使用Python Pexpect模块实现自动化交互脚本使用心得

    参考文档:https://pexpect.readthedocs.io/en/stable/ 在最近的工作中,需要使用DockerFile构建镜像。在构建镜像的过程中,有一些执行的命令是需要交互的。例如安装 tzdata (apt install tzdata),不过在使用apt安装时,可以直接使用 DEBIAN_FRONTEND=noninteractive 前缀来取消交互(至于是禁止交互还

    2023年04月25日
    浏览(40)
  • Python自动化测试之登录脚本

    前提已经安装好python、pycharm,配置了对应的环境变量。 文件–设置—项目:script----python解释器----+selenium 以谷歌浏览器为例 下载地址:https://chromedriver.chromium.org/downloads (1)先查看谷歌浏览器版本; (2)下载类似版本号的.zip,解压到pyhton环境目录下 (也可以下载到pycharm下

    2024年02月05日
    浏览(48)
  • 使用Python打造微信高效自动化操作教程

    在如今数字化时代,人们对于效率的追求越来越强烈,尤其是在工作和学习中。自动化操作成为了提高生产力的有效途径之一,而PyAutoGUI和Pyperclip作为Python中的两个强大库,为我们实现自动化操作提供了便利。本文将向大家介绍如何使用这两个库,并通过实际案例帮助读者轻

    2024年02月03日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包