# 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 页面并将它们转换为图像。该脚本使用流行的 PyMuPDF 模块,该模块以其 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 数据
需要从数据库中获取 API 数据或需要向服务器发送 API 请求。那么这个自动化脚本对你来说是一个方便的工具。使用 Urllib3 模块,可让你获取和发布 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)
# 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)