欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2023年03月23日 08:43:46   作者:丁丁貓 Codeye  
重復(fù)的任務(wù)總是耗費(fèi)時(shí)間和枯燥的。如果逐一裁剪100張照片,或者做諸如Fetching APIs、糾正拼寫和語(yǔ)法等任務(wù),所有這些都需要大量的時(shí)間。為什么不把它們自動(dòng)化呢?本文詳細(xì)介紹了10個(gè)Python自動(dòng)化腳本,感興趣的小伙伴可以閱讀一下

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

重復(fù)的任務(wù)總是耗費(fèi)時(shí)間和枯燥的。想象一下,逐一裁剪100張照片,或者做諸如Fetching APIs、糾正拼寫和語(yǔ)法等任務(wù),所有這些都需要大量的時(shí)間。為什么不把它們自動(dòng)化呢?在今天的文章中,我將與你分享10個(gè)Python自動(dòng)化腳本。

所以,請(qǐng)把這篇文章保留在你的書(shū)簽里,供以后參考。在IT行業(yè),程序員永遠(yuǎn)不會(huì)停止學(xué)習(xí)......

現(xiàn)在,讓我們開(kāi)始吧。

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、拼寫糾正

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

# 拼寫修正器
# pip 安裝 textblob
# pip install textblob
from textblob import *
def fix_paragraph_words(paragraph):
    sentence = TextBlob(paragraph)
    correction = sentence.correct()
    print(correction)
# 修復(fù)字詞拼寫
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)于10個(gè)殺手級(jí)應(yīng)用的Python自動(dòng)化腳本的文章就介紹到這了,更多相關(guān)Python自動(dòng)化腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python3 xml.etree.ElementTree支持的XPath語(yǔ)法詳解

    Python3 xml.etree.ElementTree支持的XPath語(yǔ)法詳解

    這篇文章主要介紹了Python3 xml.etree.ElementTree支持的XPath語(yǔ)法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • python 讀寫文件包含多種編碼格式的解決方式

    python 讀寫文件包含多種編碼格式的解決方式

    今天小編就為大家分享一篇python 讀寫文件包含多種編碼格式的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • 利用Opencv實(shí)現(xiàn)圖片的油畫(huà)特效實(shí)例

    利用Opencv實(shí)現(xiàn)圖片的油畫(huà)特效實(shí)例

    這篇文章主要給大家介紹了關(guān)于利用Opencv實(shí)現(xiàn)圖片的油畫(huà)特效的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • python與php實(shí)現(xiàn)分割文件代碼

    python與php實(shí)現(xiàn)分割文件代碼

    本文給大家分享的是兩個(gè)分別使用python和php實(shí)現(xiàn)的將文件分割成小文件的代碼,非常的實(shí)用有需要的小伙伴可以參考下
    2017-03-03
  • 詳解django使用include無(wú)法跳轉(zhuǎn)的解決方法

    詳解django使用include無(wú)法跳轉(zhuǎn)的解決方法

    這篇文章主要介紹了詳解django使用include無(wú)法跳轉(zhuǎn)的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 在Python的Django框架中更新數(shù)據(jù)庫(kù)數(shù)據(jù)的方法

    在Python的Django框架中更新數(shù)據(jù)庫(kù)數(shù)據(jù)的方法

    這篇文章主要介紹了在Python的Django框架中更新數(shù)據(jù)庫(kù)數(shù)據(jù),對(duì)此Django框架中提供了便利的插入和更新方法,需要的朋友可以參考下
    2015-07-07
  • 最新評(píng)論