news 2026/2/7 4:47:05

Python常用的10个自动化脚本

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Python常用的10个自动化脚本

包含编程资料、学习路线图、源代码、软件安装包等!【[点击这里]】!

01、 图片优化器

# Image Optimizing# pip install PillowimportPIL# Cropingim=PIL.Image.open("Image1.jpg")im=im.crop((34,23,100,100))# Resizingim=PIL.Image.open("Image1.jpg")im=im.resize((50,50))# Flippingim=PIL.Image.open("Image1.jpg")im=im.transpose(PIL.Image.FLIP_LEFT_RIGHT)# Rotatingim=PIL.Image.open("Image1.jpg")im=im.rotate(360)# Compressingim=PIL.Image.open("Image1.jpg")im.save("Image1.jpg",optimize=True,quality=90)# Bluringim=PIL.Image.open("Image1.jpg")im=im.filter(PIL.ImageFilter.BLUR)# Sharpeningim=PIL.Image.open("Image1.jpg")im=im.filter(PIL.ImageFilter.SHARPEN)# Set Brightnessim=PIL.Image.open("Image1.jpg")im=PIL.ImageEnhance.Brightness(im)im=im.enhance(1.5)# Set Contrastim=PIL.Image.open("Image1.jpg")im=PIL.ImageEnhance.Contrast(im)im=im.enhance(1.5)# Adding Filtersim=PIL.Image.open("Image1.jpg")im=PIL.ImageOps.grayscale(im)im=PIL.ImageOps.invert(im)im=PIL.ImageOps.posterize(im,4)# Savingim.save("Image1.jpg")

02、视频优化器

# Video Optimizer# pip install moviepyimportmoviepy.editoraspyedit# Load the Videovideo=pyedit.VideoFileClip("vid.mp4")# Trimmingvid1=video.subclip(0,10)vid2=video.subclip(20,40)final_vid=pyedit.concatenate_videoclips([vid1,vid2])# Speed up the videofinal_vid=final_vid.speedx(2)# Adding Audio to the videoaud=pyedit.AudioFileClip("bg.mp3")final_vid=final_vid.set_audio(aud)# Reverse the Videofinal_vid=final_vid.fx(pyedit.vfx.time_mirror)# Merge two videosvid1=pyedit.VideoFileClip("vid1.mp4")vid2=pyedit.VideoFileClip("vid2.mp4")final_vid=pyedit.concatenate_videoclips([vid1,vid2])# Add VFX to Videovid1=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 Videoimg1=pyedit.ImageClip("img1.jpg")img2=pyedit.ImageClip("img2.jpg")final_vid=pyedit.concatenate_videoclips([img1,img2])# Save the videofinal_vid.write_videofile("final.mp4")

03、PDF 转图片

# PDF to Images# pip install PyMuPDFimportfitzdefpdf_to_images(pdf_file):doc=fitz.open(pdf_file)forpindoc:pix=p.get_pixmap()output=f"page{p.number}.png"pix.writePNG(output)pdf_to_images("test.pdf")

04、获取 API 数据

# pip install urllib3importurllib3# Fetch API dataurl="https://api.github.com/users/psf/repos"http=urllib3.PoolManager()response=http.request('GET',url)print(response.status)print(response.data)# Post API dataurl="https://httpbin.org/post"http=urllib3.PoolManager()response=http.request('POST',url,fields={'hello':'world'})print(response.status)

05、电池指示灯

# Battery Notifier# pip instal plyerfromplyerimportnotificationimportpsutilfromtimeimportsleepwhileTrue:battery=psutil.sensors_battery()life=battery.percentiflife<50:notification.notify(title="Battery Low",message="Please connect to power source",timeout=10)sleep(60)

06、语法固定器

# Grammer Fixer# pip install happytransformerfromhappytransformerimportHappyTextToTextasHappyTTTfromhappytransformerimportTTSettingsdefGrammer_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、拼写修正

# Spell Fixer# pip install textblobfromtextblobimport*# Fixing Paragraph Spellsdeffix_paragraph_words(paragraph):sentence=TextBlob(paragraph)correction=sentence.correct()print(correction)# Fixing Words Spellsdeffix_word_spell(word):word=Word(word)correction=word.correct()print(correction)fix_paragraph_words("This is sammple tet!!")fix_word_spell("maangoo")08

08、互联网下载器

# Python Downloader# pip install internetdownloadmanagerimportinternetdownloadmanagerasidmdefDownloader(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、获取世界新闻

# World News Fetcher# pip install requestsimportrequests 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

# PySide 2# pip install PySide2fromPySide6.QtWidgetsimport*fromPySide6.QtGuiimport*importsys app=QApplication(sys.argv)window=QWidget()# Resize the Windowwindow.resize(500,500)# Set the Window Titlewindow.setWindowTitle("PySide2 Window")# Add Buttonsbutton=QPushButton("Click Me",window)button.move(200,200)# Add Label Textlabel=QLabel("Hello Medium",window)label.move(200,150)# Add Input Boxinput_box=QLineEdit(window)input_box.move(200,250)print(input_box.text())# Add Radio Buttonsradio_button=QRadioButton("Radio Button",window)radio_button.move(200,300)# Add Checkboxcheckbox=QCheckBox("Checkbox",window)checkbox.move(200,350)# Add Sliderslider=QSlider(window)slider.move(200,400)# Add Progress Barprogress_bar=QProgressBar(window)progress_bar.move(200,450)# Add Imageimage=QLabel(window)image.setPixmap(QPixmap("image.png"))# Add Message Boxmsg=QMessageBox(window)msg.setText("Message Box")msg.setStandardButtons(QMessageBox.Ok|QMessageBox.Cancel)window.show()sys.exit(app.exec())

🟢总结

🟡文末福利

🔴包含编程资料、学习路线图、源代码、软件安装包等!【点击这里】领取!

可以扫描下方二维码领取【保证100%免费

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/2/6 1:19:38

AI应用架构师必知必会:智能Web3应用开发框架要点

AI应用架构师必知必会:智能Web3应用开发框架核心要点解析 元数据框架 标题 AI应用架构师必知必会:智能Web3应用开发框架核心要点解析 关键词 AI应用架构、Web3开发框架、智能合约与AI融合、去中心化机器学习、Web3 AI系统设计、零知识证明、联邦学习 摘要 随着Web3(去…

作者头像 李华
网站建设 2026/1/30 14:58:48

Transformer模型太大跑不动?TensorRT镜像来救场

Transformer模型太大跑不动&#xff1f;TensorRT镜像来救场 在大模型落地的战场上&#xff0c;性能瓶颈常常不是来自算法本身&#xff0c;而是部署环节——你训练好的BERT或T5模型一放进生产环境&#xff0c;GPU显存爆了、推理延迟飙升到几百毫秒&#xff0c;QPS连预期的零头都…

作者头像 李华
网站建设 2026/1/29 23:21:26

Sidecar不就是在Pod里多跑一个容器吗!

深入理解云原生时代的核心设计模式乍看之下&#xff0c;Sidecar 模式确实只是在 Pod 里多运行一个容器而已。但这种表面理解&#xff0c;就像说“互联网不过是一堆电缆和服务器”一样&#xff0c;忽略了其背后的精妙设计思想和革命性价值。今天&#xff0c;我们就来深入探讨这个…

作者头像 李华