最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

分享十個Python超級好用提高工作效率的自動化腳本

 更新時間:2022年11月25日 11:39:38   作者:宋宋講編程  
在這個自動化時代,我們有很多重復(fù)無聊的工作要做。?想想這些你不再需要一次又一次地做的無聊的事情,讓它自動化,讓你的生活更輕松。本文分享了10個Python自動化腳本,希望對大家有所幫助

重復(fù)性任務(wù)總是耗時且無聊,想一想你想要一張一張地裁剪 100 張照片或 Fetch API、糾正拼寫和語法等工作,所有這些任務(wù)都很耗時,為什么不自動化它們呢?在今天的文章中,我將與你分享 10 個 Python 自動化腳本。

所以,請你把這篇文章放在你的收藏清單上,以備不時之需,在IT行業(yè)里,程序員的學(xué)習(xí)永無止境……

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

圖片優(yōu)化器

使用這個很棒的自動化腳本,可以幫助把圖像處理的更好,你可以像在 Photoshop 中一樣編輯它們。

該腳本使用流行的是 Pillow 模塊,你可以在下面找到優(yōu)化圖像所需的大部分方法。

  • 在你的圖像編輯項目中使用
  • 在你的 Python 項目中使用它
  • 批量圖像編輯

更多

# 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)化器

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

  • 創(chuàng)建完整的視頻編輯器
  • 在你的 Python 項目中使用
  • 修剪視頻
  • 從圖像制作視頻

更多

# 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)圖片

這個小型自動化腳本可以方便地獲取整個 PDF 頁面并將它們轉(zhuǎn)換為圖像。該腳本使用流行的 PyMuPDF 模塊,該模塊以其 PDF 文本提取而聞名。

  • 在你的 PDF 項目中使用它
  • 批量 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ù)庫中獲取 API 數(shù)據(jù)或需要向服務(wù)器發(fā)送 API 請求。那么這個自動化腳本對你來說是一個方便的工具。使用 Urllib3 模塊,可讓你獲取和發(fā)布 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)

電池指示燈

這個方便的腳本可以讓你設(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)

語法固定器

厭倦了校對你的長文章或文本,然后,你可以試試這個自動化腳本,它將掃描你的文本并糾正語法錯誤,這個很棒的腳本使用 Happtransformer 模塊,這是一個機器學(xué)習(xí)模塊,經(jīng)過訓(xùn)練可以修復(fù)文本中的語法錯誤。

# 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)

拼寫修正

這個很棒的腳本將幫助你糾正你的文本單詞拼寫錯誤。你可以在下面找到腳本,將告訴你如何修復(fù)句子中的單個單詞或多個單詞。

# 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 相冊
  • 在你的項目中使用
  • 下載視頻和音樂

更多

# 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")

獲取世界新聞

使用此自動化腳本讓你隨時了解每日世界新聞,你可以使用任何語言從任何國家/地區(qū)獲取新聞。這個 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())

PySide2 GUI

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

PySide2 還支持跨平臺,對開發(fā)人員非常友好,請查看下面的代碼。

# 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)于分享十個Python超級好用提高工作效率的自動化腳本的文章就介紹到這了,更多相關(guān)Python自動化腳本內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Jinja2過濾器的使用、控制語句示例詳解

    Jinja2過濾器的使用、控制語句示例詳解

    在Python中,如果需要對某個變量進(jìn)行處理,我們可以通過函數(shù)來實現(xiàn),這篇文章主要介紹了Jinja2過濾器的使用、控制語句,需要的朋友可以參考下
    2023-03-03
  • 搞清楚 Python traceback的具體使用方法

    搞清楚 Python traceback的具體使用方法

    這篇文章主要介紹了搞清楚 Python traceback的具體使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • Python實現(xiàn)的彩票機選器實例

    Python實現(xiàn)的彩票機選器實例

    這篇文章主要介紹了Python實現(xiàn)彩票機選器的方法,可以模擬彩票號碼的隨機生成功能,需要的朋友可以參考下
    2015-06-06
  • python多線程之事件Event的使用詳解

    python多線程之事件Event的使用詳解

    本篇文章主要介紹了python多線程之事件Event的使用詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • Django實現(xiàn)發(fā)送郵件找回密碼功能

    Django實現(xiàn)發(fā)送郵件找回密碼功能

    在各大網(wǎng)站上,一定都遇到過找回密碼的問題,通常采用的方式是通過發(fā)送帶有驗證碼的郵件進(jìn)行身份驗證,本文將介紹通過Django實現(xiàn)郵件找回密碼功能,需要的朋友可以參考下
    2019-08-08
  • Python HTMLTestRunner如何下載生成報告

    Python HTMLTestRunner如何下載生成報告

    這篇文章主要介紹了Python HTMLTestRunner如何下載生成報告,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • Python內(nèi)置函數(shù)int()用法簡單介紹

    Python內(nèi)置函數(shù)int()用法簡單介紹

    這篇文章主要給大家介紹了關(guān)于Python內(nèi)置函數(shù)int()用法的相關(guān)資料,int()函數(shù)常用來把其他類型轉(zhuǎn)換為整數(shù),文中通過代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用python具有一定的參考借鑒價值,需要的朋友可以參考下
    2024-05-05
  • Python對列表去重的多種方法(四種方法)

    Python對列表去重的多種方法(四種方法)

    開發(fā)中對數(shù)組、列表去重是非常常見的需求,對一個list中的id進(jìn)行去重,有下面幾種方法,具體內(nèi)容詳情大家參考下本文
    2017-12-12
  • Python格式化輸出字符串方法小結(jié)【%與format】

    Python格式化輸出字符串方法小結(jié)【%與format】

    這篇文章主要介紹了Python格式化輸出字符串方法,結(jié)合實例形式總結(jié)分析了使用%與format函數(shù)進(jìn)行字符串格式化操作相關(guān)實現(xiàn)技巧與注意事項,需要的朋友可以參考下
    2018-10-10
  • 解決python刪除文件的權(quán)限錯誤問題

    解決python刪除文件的權(quán)限錯誤問題

    下面小編就為大家分享一篇解決python刪除文件的權(quán)限錯誤問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04

最新評論

防城港市| 瑞昌市| 申扎县| 兴仁县| 新邵县| 新疆| 嵩明县| 安仁县| 年辖:市辖区| 绥阳县| 繁峙县| 陈巴尔虎旗| 抚宁县| 社旗县| 建昌县| 玉田县| 合作市| 临高县| 五原县| 普兰店市| 崇信县| 泾阳县| 鲁山县| 万荣县| 汶川县| 安庆市| 丰台区| 连平县| 临汾市| 嘉义县| 双辽市| 宜宾市| 大同市| 固始县| 广宁县| 秀山| 聊城市| 台湾省| 绥化市| 天等县| 铜梁县|