反复性使命总是耗时且无聊,想一想你想要一张一张地裁剪100张照片或Fetch API、改正拼写和语法等工作,一切这些使命都很耗时,为什么不自动化它们呢?在明天的文章中,我将与你分享10个Python自动化剧本。 所以,请你把这篇文章放在你的收藏清单上,以备不时之需,在IT行业里,法式员的进修永无尽头…… 现在,让我们起头吧。 1、 图片优化器 利用这个很棒的自动化剧本,可以帮助把图像处置的更好,你可以像在 Photoshop 中一样编辑它们。 该剧本利用风行的是 Pillow 模块,你可以鄙人面找到优化图像所需的大部分方式。
更多 # 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") 2、视频优化器 经过利用以下自动化剧本,你不但可以利用 Python 来优化视频,还可以利用它来优化图像。该剧本利用 Moviepy 模块,答应你修剪、增加音频、设备视频速度、增加 VFX 等等。
更多 # 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") 3、PDF 转图片 这个小型自动化剧本可以方便地获得全部 PDF 页面并将它们转换为图像。该剧本利用风行的 PyMuPDF 模块,该模块以其 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") 4、获得 API 数据 需要从数据库中获得 API 数据或需要向办事器发送 API 请求。那末这个自动化剧本对你来说是一个方便的工具。利用 Urllib3 模块,可让你获得和公布 API 请求。 # pip install urllib3import 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) 5、电池指示灯 这个方便的剧本可以让你设备你想要获得告诉的电池百分比,该剧本利用 Pyler 停止告诉,利用 Psutil 获得当前的电池百分比。 # 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) 6、语法牢固器 厌倦了校订你的长文章或文本,然后,你可以试试这个自动化剧本,它将扫描你的文本并改正语法毛病,这个很棒的剧本利用 HAPPtransformer 模块,这是一个机械进修模块,经过练习可以修复文本中的语法毛病。 # 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) 7、拼写批改 这个很棒的剧本将帮助你改正你的文本单词拼写毛病。你可以鄙人面找到剧本,将告诉你若何修复句子中的单个单词或多个单词。 # 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") 8、互联网下载器 你们能够利用下载软件从 Internet 下载照片或视频,但现在你可以利用 Python IDM 模块建立自己的下载器。
更多 # 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") 9、获得天下消息 利用此自动化剧本让你随时领会逐日天下消息,你可以利用任何说话从任何国家/地域获得消息。这个 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()) 10、PySide2 GUI 这个自动化剧本将帮助你利用 PySide2 Gui 模块建立你的 GUI 利用法式。你可以鄙人面找到起头开辟体面的现代利用法式所需的每种方式。 PySide2 还支持跨平台,对开辟职员很是友爱,请检察下面的代码。 # 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()) 最初的想法 明天这篇文章内容就到这里了,我希望你能为你的下一个开辟项目找到一些有用的自动化剧本。 假如您喜好这篇文章,请与你的开辟者朋友分享他,由于也答应以帮助到他。 |
小编在之前就介绍过很多油猴里的神器插件,这里给大家总结几款经典中的经典。01Usersc
shell是外壳的意思,就是操作系统的外壳。我们可以通过shell命令来操作和控制操作系统
作者:厚昌学院特聘讲师,厚昌学院顾问团队核心成员,从事互联网行业从事互联网行业8
前言「油猴脚本」是一段脚本代码,通过它可以让浏览器实现各种各样的扩展功能,和浏览
shell 是一个应用程序,它连接了用户和 Linux 内核,让用户能够更加高效、安全、低成
关注扩展迷、喜欢折腾电脑的小伙伴们,应该都对各种各样的浏览器插件不陌生了。浏览器
Tampermonkey 是一款免费的浏览器扩展和最为流行的用户脚本管理器,它适用于 Chrome,
油猴脚本管理器的超详细下载安装使用教程——新手必看油猴可以帮你干什么:全网VIP视
参考文章和视频:将iPad作为Mac Mini主屏幕的实现方法视频:无屏自动启动随航 iPad作为M
在运营短视频时,你有没有遇到过这样的问题:1、拍了一半发现拍摄场景不行;2、拍摄过
我们先看一下这个脚本的下载效果。我是100M的宽带,这直接能飙到20MB/s,所以下载速度
写脚本?对于没有视频背景的朋友来说可能就会有疑问,脚本是什么?不应该是电影,电视
本内容来源于@什么值得买APP,观点仅代表作者本人 |作者:Stark-C大家好,我是Stark-
初次见面,大家好。相信熟悉浏览器的都知道,尤其是大名鼎鼎的Chrome浏览器,丰富的
从历史上看,shell一直是类Unix系统的原生命令行解释器。多年来,它已被证明是Unix的
有人说,网红行业的现状是江山代有才人出,各领风骚“好几天”。的确,即便是行业顶流
最近115调整了接口,导致115转存助手ui优化版3.8.1版本无法转存或获取SHA1。有大神在
根据第49次《中国互联网络发展状况统计报告》数据,截至2022年12月,我国网络视频(含
Shell脚本编程难,难于上青天!这话不假,尤其很多程序员新人,学了几个月Shell脚本写
在上期我们做了个形象的比喻,把短视频制作比喻成我们造房子,前面我们已经带领大家打
声明:本站内容由网友分享或转载自互联网公开发布的内容,如有侵权请反馈到邮箱 1415941@qq.com,我们会在3个工作日内删除,加急删除请添加站长微信:15314649589
Copyright @ 2022-2044 杭州共生网络 www.gongshengyun.cn Powered by Discuz!