news 2026/4/18 6:45:42

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/4/3 18:48:38

视觉大模型部署难题破解:基于TensorRT镜像的完整方案

视觉大模型部署难题破解&#xff1a;基于TensorRT镜像的完整方案 在智能制造车间的质检线上&#xff0c;一台工业相机每秒捕捉数百帧高清图像&#xff0c;系统需要在毫秒级内判断是否存在微米级缺陷&#xff1b;在自动驾驶车辆中&#xff0c;多路摄像头实时输入的画面必须被即时…

作者头像 李华
网站建设 2026/4/16 15:08:39

书籍-普鲁斯特《追忆似水年华》

普鲁斯特《追忆似水年华》详细介绍 书籍基本信息 书名&#xff1a;追忆似水年华 作者&#xff1a;马塞尔普鲁斯特&#xff08;Marcel Proust&#xff0c;1871-1922&#xff09; 成书时间&#xff1a;1913-1927年&#xff08;分七卷陆续出版&#xff09; 卷数&#xff1a;七卷 类…

作者头像 李华
网站建设 2026/4/15 16:45:47

金融风控实时推理场景下TensorRT镜像的应用案例

金融风控实时推理场景下TensorRT镜像的应用实践 在现代金融系统中&#xff0c;一笔交易从发起、验证到完成往往发生在毫秒之间。而在这短暂的时间窗口里&#xff0c;风控模型必须完成对用户行为的全面评估——是否存在盗刷风险&#xff1f;是否涉及洗钱链条&#xff1f;这些判断…

作者头像 李华
网站建设 2026/4/9 9:16:58

我用7款AI写论文工具,5分钟生成1万字带真实参考文献,亲测有效

摘要&#xff1a;本文通过一位研究生的真实经历&#xff0c;深度测评了7款主流AI论文写作工具。从文献检索到全文生成&#xff0c;从格式排版到降重优化&#xff0c;本文将为你揭示如何高效、合规地利用AI辅助完成高质量学术论文。核心推荐瑞达写作&#xff0c;以其一站式、低A…

作者头像 李华
网站建设 2026/4/15 5:09:10

基于TensorRT镜像的多模型并发推理系统设计实践

基于TensorRT镜像的多模型并发推理系统设计实践 在当今AI服务日益普及的背景下&#xff0c;从智能客服到自动驾驶&#xff0c;从医疗影像分析到实时视频处理&#xff0c;用户对响应速度和系统吞吐量的要求越来越高。一个训练完成的深度学习模型&#xff0c;若无法在生产环境中…

作者头像 李华