溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python自動(dòng)化腳本的應(yīng)用場(chǎng)景有哪些

發(fā)布時(shí)間:2023-05-08 11:16:31 來(lái)源:億速云 閱讀:91 作者:iii 欄目:編程語(yǔ)言

這篇“Python自動(dòng)化腳本的應(yīng)用場(chǎng)景有哪些”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“Python自動(dòng)化腳本的應(yīng)用場(chǎng)景有哪些”文章吧。

10個(gè)殺手級(jí)應(yīng)用的Python自動(dòng)化腳本

01、圖像優(yōu)化器

這個(gè)偉大的自動(dòng)化腳本可以幫助你更好地處理圖片,你可以像在Photoshop中一樣編輯它們。

該腳本使用流行的Pillow模塊。

# 圖像優(yōu)化
# pip install Pillow
import PIL
# 裁剪 
im = PIL.Image.open("Image1.jpg")
im = im.crop((34, 23, 100, 100))
# 調(diào)整大小
im = PIL.Image.open("Image1.jpg")
im = im.resize((50, 50))
# 翻轉(zhuǎn)
im = PIL.Image.open("Image1.jpg")
im = im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
# 旋轉(zhuǎn)
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)
# 設(shè)置亮度
im = PIL.Image.open("Image1.jpg")
im = PIL.ImageEnhance.Brightness(im)
im = im.enhance(1.5)
# 設(shè)置對(duì)比度
im = PIL.Image.open("Image1.jpg")
im = PIL.ImageEnhance.Contrast(im)
im = im.enhance(1.5)
# 添加過(guò)濾器
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、視頻優(yōu)化器

通過(guò)下面的自動(dòng)化腳本,你不僅可以用Python來(lái)優(yōu)化視頻,還可以用它來(lái)優(yōu)化圖像。該腳本使用Moviepy模塊,它允許你修剪、添加音頻、設(shè)置視頻速度、添加VFX等。

# 視頻優(yōu)化器
# 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)
# 反轉(zhuǎn)視頻
final_vid = final_vid.fx(pyedit.vfx.time_mirror)
# 合并兩個(gè)視頻
vid1 = pyedit.VideoFileClip("vid1.mp4")
vid2 = pyedit.VideoFileClip("vid2.mp4")
final_vid = pyedit.concatenate_videoclips([vid1, vid2])
# 在視頻中添加視覺(jué)特效
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、將PDF轉(zhuǎn)換為圖像

這個(gè)小的自動(dòng)化腳本可以很容易地檢索整個(gè)PDF頁(yè)面并將其轉(zhuǎn)換為圖像。該腳本使用了流行的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數(shù)據(jù)

如果你需要從數(shù)據(jù)庫(kù)中獲取API數(shù)據(jù),或者需要向服務(wù)器發(fā)送API請(qǐng)求,這個(gè)自動(dòng)化腳本是你的一個(gè)便利工具。使用Urlib3模塊,你可以獲取和發(fā)布API請(qǐng)求。

# pip install urllib3
輸入urllib3
# 獲取API數(shù)據(jù)
url = "https://api.github.com/users/psf/repos"
http = urllib3.PoolManager()
response = http.request('GET', url)
print(response.status)
print(response.data)
# 發(fā)布API數(shù)據(jù)
url = "https://httpbin.org/post"
http = urllib3.PoolManager()
response = http.request('POST', url, fields={'hello': 'world'})
print(response.status)
05、電池指示燈

這個(gè)方便的腳本允許你設(shè)置你想接收通知的電池百分比。該腳本使用Pyler進(jìn)行通知,并使用Psutil來(lái)獲取當(dāng)前的電池百分比。

# 電池通知器
# 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、語(yǔ)法修正器

厭倦了校對(duì)你的長(zhǎng)篇文章或文本?那么,你可以試試這個(gè)自動(dòng)腳本,它將掃描你的文本并糾正語(yǔ)法錯(cuò)誤。這個(gè)偉大的腳本使用了Happtransformer模塊,它是一個(gè)機(jī)器學(xué)習(xí)模塊,經(jīng)過(guò)訓(xùn)練可以修正文本中的語(yǔ)法錯(cuò)誤。

# 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、拼寫(xiě)糾正

這個(gè)偉大的腳本將幫助你糾正文本單詞中的拼寫(xiě)錯(cuò)誤。你可以找到下面的腳本,它將告訴你如何修正一個(gè)句子中的單個(gè)或多個(gè)單詞。

# 拼寫(xiě)修正器
# pip 安裝 textblob
# pip install textblob
from textblob import *
def fix_paragraph_words(paragraph):
    sentence = TextBlob(paragraph)
    correction = sentence.correct()
    print(correction)
# 修復(fù)字詞拼寫(xiě)
def fix_word_spell(word):
    word = Word(word)
    更正 = word.correct()
    print(correction)
fix_paragraph_words("this is sammple tet!!")
fix_word_spell("maangoo")
08、互聯(lián)網(wǎng)下載器

你可能使用下載軟件從互聯(lián)網(wǎng)上下載照片或視頻,但現(xiàn)在你可以使用Python IDM模塊創(chuàng)建自己的下載器。

# 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、獲取世界新聞

使用這個(gè)自動(dòng)腳本,可以隨時(shí)以任何國(guó)家/地區(qū)的任何語(yǔ)言更新每日的世界新聞。這個(gè)API允許你每天免費(fèi)獲得50條新聞。

# 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

這個(gè)自動(dòng)化腳本將幫助你使用PySide2 Gui模塊創(chuàng)建你的GUI應(yīng)用程序。你可以在下面找到開(kāi)始開(kāi)發(fā)現(xiàn)代應(yīng)用程序的前端所需的每一種方法。

# PySide2 
# pip install PySide2
from PySide6.QtWidgets import *
from PySide6.QtGui import *
app = QApplication(sys.argv)
window = QWidget()
# 調(diào)整窗口的大小
window.resize(500, 500)
# 設(shè)置窗口標(biāo)題
window.setWindowTitle("PySide2 Window")
# 添加按鈕
button = QPushButton("Click Me", window)
button.move(200, 200)
# 添加標(biāo)簽文本
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)
# 添加復(fù)選框
checkbox = QCheckBox("Checkbox", window)
checkbox.move(200, 350)
# 添加滑塊
slider = QSlider(window)
slider.move(200, 400)
# 添加進(jìn)度條
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())

以上就是關(guān)于“Python自動(dòng)化腳本的應(yīng)用場(chǎng)景有哪些”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI