分享十個(gè)Python超級(jí)好用提高工作效率的自動(dòng)化腳本
重復(fù)性任務(wù)總是耗時(shí)且無聊,想一想你想要一張一張地裁剪 100 張照片或 Fetch API、糾正拼寫和語法等工作,所有這些任務(wù)都很耗時(shí),為什么不自動(dòng)化它們呢?在今天的文章中,我將與你分享 10 個(gè) Python 自動(dòng)化腳本。
所以,請(qǐng)你把這篇文章放在你的收藏清單上,以備不時(shí)之需,在IT行業(yè)里,程序員的學(xué)習(xí)永無止境……
現(xiàn)在,讓我們開始吧。
圖片優(yōu)化器
使用這個(gè)很棒的自動(dòng)化腳本,可以幫助把圖像處理的更好,你可以像在 Photoshop 中一樣編輯它們。
該腳本使用流行的是 Pillow 模塊,你可以在下面找到優(yōu)化圖像所需的大部分方法。
- 在你的圖像編輯項(xiàng)目中使用
- 在你的 Python 項(xiàng)目中使用它
- 批量圖像編輯
更多
# 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")
視頻優(yōu)化器
通過使用以下自動(dòng)化腳本,你不僅可以使用 Python 來優(yōu)化視頻,還可以使用它來優(yōu)化圖像。該腳本使用 Moviepy 模塊,允許你修剪、添加音頻、設(shè)置視頻速度、添加 VFX 等等。
- 創(chuàng)建完整的視頻編輯器
- 在你的 Python 項(xiàng)目中使用
- 修剪視頻
- 從圖像制作視頻
更多
# 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")
PDF 轉(zhuǎn)圖片
這個(gè)小型自動(dòng)化腳本可以方便地獲取整個(gè) PDF 頁面并將它們轉(zhuǎn)換為圖像。該腳本使用流行的 PyMuPDF 模塊,該模塊以其 PDF 文本提取而聞名。
- 在你的 PDF 項(xiàng)目中使用它
- 批量 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")
獲取 API 數(shù)據(jù)
需要從數(shù)據(jù)庫(kù)中獲取 API 數(shù)據(jù)或需要向服務(wù)器發(fā)送 API 請(qǐng)求。那么這個(gè)自動(dòng)化腳本對(duì)你來說是一個(gè)方便的工具。使用 Urllib3 模塊,可讓你獲取和發(fā)布 API 請(qǐng)求。
# 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)
電池指示燈
這個(gè)方便的腳本可以讓你設(shè)置你想要得到通知的電池百分比,該腳本使用 Pyler 進(jìn)行通知,使用 Psutil 獲取當(dāng)前的電池百分比。
# 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)
語法固定器
厭倦了校對(duì)你的長(zhǎng)文章或文本,然后,你可以試試這個(gè)自動(dòng)化腳本,它將掃描你的文本并糾正語法錯(cuò)誤,這個(gè)很棒的腳本使用 Happtransformer 模塊,這是一個(gè)機(jī)器學(xué)習(xí)模塊,經(jīng)過訓(xùn)練可以修復(fù)文本中的語法錯(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)
拼寫修正
這個(gè)很棒的腳本將幫助你糾正你的文本單詞拼寫錯(cuò)誤。你可以在下面找到腳本,將告訴你如何修復(fù)句子中的單個(gè)單詞或多個(gè)單詞。
# 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")
互聯(lián)網(wǎng)下載器
你們可能使用下載軟件從 Internet 下載照片或視頻,但現(xiàn)在你可以使用 Python IDM 模塊創(chuàng)建自己的下載器。
- 下載 Google 相冊(cè)
- 在你的項(xià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")
獲取世界新聞
使用此自動(dòng)化腳本讓你隨時(shí)了解每日世界新聞,你可以使用任何語言從任何國(guó)家/地區(qū)獲取新聞。這個(gè) API 讓你每天免費(fèi)獲取 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())
PySide2 GUI
這個(gè)自動(dòng)化腳本將幫助你使用 PySide2 Gui 模塊創(chuàng)建你的 GUI 應(yīng)用程序。你可以在下面找到開始開發(fā)體面的現(xiàn)代應(yīng)用程序所需的每種方法。
PySide2 還支持跨平臺(tái),對(duì)開發(fā)人員非常友好,請(qǐng)查看下面的代碼。
# 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())
到此這篇關(guān)于分享十個(gè)Python超級(jí)好用提高工作效率的自動(dòng)化腳本的文章就介紹到這了,更多相關(guān)Python自動(dòng)化腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 20個(gè)超實(shí)用Python自動(dòng)化腳本分享
- 分享10個(gè)拿來即用的Python自動(dòng)化腳本
- 10個(gè)殺手級(jí)應(yīng)用的Python自動(dòng)化腳本
- 5個(gè)Python殺手級(jí)的自動(dòng)化腳本分享
- 分享4個(gè)Python中的非常好用的自動(dòng)化腳本
- 分享十個(gè)Python提高工作效率的自動(dòng)化腳本
- 八個(gè)超級(jí)好用的Python自動(dòng)化腳本(小結(jié))
- 十個(gè)簡(jiǎn)單使用的Python自動(dòng)化腳本分享
- 分享5個(gè)方便好用的Python自動(dòng)化腳本
- 10個(gè)常用python自動(dòng)化腳本
相關(guān)文章
Python requests模塊cookie實(shí)例解析
這篇文章主要介紹了Python requests模塊cookie實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04python 對(duì)給定可迭代集合統(tǒng)計(jì)出現(xiàn)頻率,并排序的方法
今天小編就為大家分享一篇python 對(duì)給定可迭代集合統(tǒng)計(jì)出現(xiàn)頻率,并排序的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10Python Selenium XPath根據(jù)文本內(nèi)容查找元素的方法
這篇文章主要介紹了Python Selenium XPath根據(jù)文本內(nèi)容查找元素的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12Django項(xiàng)目搭建之實(shí)現(xiàn)簡(jiǎn)單的API訪問
這篇文章主要給大家介紹了關(guān)于Django項(xiàng)目搭建之實(shí)現(xiàn)簡(jiǎn)單的API訪問的相關(guān)資料,文中通過圖文以及示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-02-02python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告
這篇文章主要給大家介紹了關(guān)于python自動(dòng)化之如何利用allure生成測(cè)試報(bào)告的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05django數(shù)據(jù)關(guān)系一對(duì)多、多對(duì)多模型、自關(guān)聯(lián)的建立
這篇文章主要介紹了django數(shù)據(jù)關(guān)系一對(duì)多、多對(duì)多模型、自關(guān)聯(lián)的建立2019-07-07