




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第Python自動化腳本的幾種應(yīng)用場景01、圖像優(yōu)化器
這個偉大的自動化腳本可以幫助你更好地處理圖片,你可以像在Photoshop中一樣編輯它們。
該腳本使用流行的Pillow模塊。
#圖像優(yōu)化
#pipinstallPillow
importPIL
#裁剪
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))
im=PIL.Image.open(Image1.jpg)
im=im.transpose(PIL.Image.FLIP_LEFT_RIGHT)
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è)置對比度
im=PIL.Image.open(Image1.jpg)
im=PIL.ImageEnhance.Contrast(im)
im=im.enhance(1.5)
#添加過濾器
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)化器
通過下面的自動化腳本,你不僅可以用Python來優(yōu)化視頻,還可以用它來優(yōu)化圖像。該腳本使用Moviepy模塊,它允許你修剪、添加音頻、設(shè)置視頻速度、添加VFX等。
#視頻優(yōu)化器
#pipinstallmoviepy
importmoviepy.editoraspyedit
#加載視頻
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)
#合并兩個視頻
vid1=pyedit.VideoFileClip(vid1.mp4)
vid2=pyedit.VideoFileClip(vid2.mp4)
final_vid=pyedit.concatenate_videoclips([vid1,vid2])
#在視頻中添加視覺特效
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)換為圖像
這個小的自動化腳本可以很容易地檢索整個PDF頁面并將其轉(zhuǎn)換為圖像。該腳本使用了流行的PyMuPDF模塊,該模塊以其PDF文本提取而聞名。
#PDFtoImages
#pipinstallPyMuPDF
importfitz
defpdf_to_images(pdf_file):
doc=fitz.open(pdf_file)
forpindoc:
pix=p.get_pixmap()
output=fpage{p.number}.png
pix.writePNG(output)
pdf_to_images(test.pdf)
04、獲取API數(shù)據(jù)
如果你需要從數(shù)據(jù)庫中獲取API數(shù)據(jù),或者需要向服務(wù)器發(fā)送API請求,這個自動化腳本是你的一個便利工具。使用Urlib3模塊,你可以獲取和發(fā)布API請求。
#pipinstallurllib3
輸入urllib3
#獲取API數(shù)據(jù)
url=/users/psf/repos
http=urllib3.PoolManager()
response=http.request(GET,url)
print(response.status)
print(response.data)
#發(fā)布API數(shù)據(jù)
url=/post
http=urllib3.PoolManager()
response=http.request(POST,url,fields={hello:world})
print(response.status)
05、電池指示燈
這個方便的腳本允許你設(shè)置你想接收通知的電池百分比。該腳本使用Pyler進(jìn)行通知,并使用Psutil來獲取當(dāng)前的電池百分比。
#電池通知器
#pipinstalplyer
fromplyerimportnotification
importpsutil
fromtimeimportsleep
whileTrue:
battery=psutil.sensors_battery()
life=battery.percent
#壽命=電池百分比
iflife50:
notification.notify(
title=BatteryLow#電池電量不足
message=Pleaseconnecttopowersource,
timeout=10
sleep(60)
06、語法修正器
厭倦了校對你的長篇文章或文本?那么,你可以試試這個自動腳本,它將掃描你的文本并糾正語法錯誤。這個偉大的腳本使用了Happtransformer模塊,它是一個機器學(xué)習(xí)模塊,經(jīng)過訓(xùn)練可以修正文本中的語法錯誤。
#GrammerFixer
#pipinstallhappytransformer
fromhappytransformerimportHappyTextToTextasHappyTTT
fromhappytransformerimportTTSettings
defGrammer_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(CorrectedText:,corrected.text)
Text=Thisissmpletetwehowknowthis
Grammer_Fixer(Text)
07、拼寫糾正
這個偉大的腳本將幫助你糾正文本單詞中的拼寫錯誤。你可以找到下面的腳本,它將告訴你如何修正一個句子中的單個或多個單詞。
#拼寫修正器
#pip安裝textblob
#pipinstalltextblob
fromtextblobimport*
deffix_paragraph_words(paragraph):
sentence=TextBlob(paragraph)
correction=sentence.correct()
print(correction)
#修復(fù)字詞拼寫
deffix_word_spell(word):
word=Word(word)
更正=word.correct()
print(correction)
fix_paragraph_words(thisissammpletet!!)
fix_word_spell(maangoo)
08、互聯(lián)網(wǎng)下載器
你可能使用下載軟件從互聯(lián)網(wǎng)上下載照片或視頻,但現(xiàn)在你可以使用PythonIDM模塊創(chuàng)建自己的下載器。
#PythonDownloader
#pipinstallinternetdownloadmanager
importinternetdownloadmanagerasidm
defDownloader(url,output):
pydownloader=idm.Downloader(worker=20,
part_size=1024*1024*10,
resumable=True,)
pydownloader.download(url,output)
Downloader(Linkurl,image.jpg)
Downloader(Linkurl,video.mp4)
09、獲取世界新聞
使用這個自動腳本,可以隨時以任何國家/地區(qū)的任何語言更新每日的世界新聞。這個API允許你每天免費獲得50條新聞。
#pipinstallrequests
importrequests
ApiKey=YOUR_API_KEY
url=/search-newstext=hurricaneapi-key={ApiKey}
headers={
Accept:application/json
response=requests.get(url,headers=headers)
print(News:,response.json())
10、PySide2GUI
這個自動化腳本將幫助你使用PySide2Gui模塊創(chuàng)建你的GUI應(yīng)用程序。你可以在下面找到開始開發(fā)現(xiàn)代應(yīng)用程序的前端所需的每一種方法。
#PySide2
#pipinstallPySide2
fromPySide6.QtWidgetsimport*
fromPySide6.QtGuiimport*
app=QApplication(sys.argv)
window=QWidget()
#調(diào)整窗口的大小
window.resize(500,500)
#設(shè)置窗口標(biāo)題
window.setWindowTitle(PySide2Window)
#添加按鈕
button=QPushButton(ClickMe,window)
button.move(200,200)
#添加標(biāo)簽文本
label=QLabel(HelloMedium,window)
label.move(200,150)
#添加輸入框
input_box=QLineEdit(window)
input_box.move(200,250)
print(input_box.text())
#添加單選按鈕
radio_button=QRadioButton(RadioButton,window)
radio_button.move(200,300)
#添加復(fù)選框
checkbox=QCheckBox(Checkbox,window)
checkbox.move(200,350)
#添加滑塊
slider=QSlider(window)
slider.move(200,400)
#
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 辦公自動化中的節(jié)能減排技術(shù)應(yīng)用案例分享
- 醫(yī)療領(lǐng)域中區(qū)塊鏈技術(shù)的安全透明實踐
- 十二指腸先天性狹窄的臨床護(hù)理
- 企業(yè)級應(yīng)用如何通過區(qū)塊鏈確保商業(yè)版權(quán)的完整性
- 個人提成合同范例
- 醫(yī)療信息透明化進(jìn)程中的區(qū)塊鏈技術(shù)作用
- 醫(yī)療AI引領(lǐng)健康管理新潮流
- 代購入駐合同標(biāo)準(zhǔn)文本
- 區(qū)塊鏈賦能投票系統(tǒng)教育領(lǐng)域的創(chuàng)新實踐
- 匠心獨運教育領(lǐng)域的創(chuàng)新實踐與現(xiàn)代審美融合
- 華為服務(wù)采購流程
- 油氣管道安全監(jiān)測技術(shù)
- JGT312-2011 遇水膨脹止水膠
- 高中化學(xué)新課標(biāo)下大單元教學(xué)設(shè)計
- 高中生社區(qū)服務(wù)、生社會實踐活動記錄表
- 園林景觀工程設(shè)計任務(wù)書范本
- 美團外賣騎手獎罰制度
- 文物鑒賞講義-課件
- 個體工商戶轉(zhuǎn)讓協(xié)議書
- 【淺析汽車發(fā)動機的維護(hù)與保養(yǎng)4600字(論文)】
- 數(shù)學(xué)中的整體思想
評論
0/150
提交評論