自動化された生産ラインや自動化されたオフィスなどの言葉を聞いたことがある人に比べて、人間の介入なしに機械が自らさまざまな作業を完了できるため、作業効率が大幅に向上します。
プログラミングの世界には、さまざまなタスクを完了するためのさまざまな自動化スクリプトがあります。
特に、Python は構文がシンプルで理解しやすく、豊富なサードパーティ ツール ライブラリがあるため、自動スクリプトの作成に非常に適しています。
今回は、Python を使用して、仕事で使用できるいくつかの自動化シナリオを実装します。
1. Web ニュースを自動的に読む
このスクリプトは Web ページからテキストをキャプチャし、それを自動的に音声で読み上げます。ニュースを聞きたい場合に適しています。
コードは 2 つの部分に分かれており、1 つはクローラーを通じて Web ページのテキストをクロールする部分、もう 1 つは読み上げツールを通じてテキストを読み上げる部分です。
必要なサードパーティ ライブラリ:
Beautiful Soup - 古典的な HTML/XML テキスト パーサー、クロールされた Web ページ情報の抽出に使用されます
requests - 逆 Tian の HTTP で簡単に使用できますWeb ページにリクエストを送信してデータを取得するために使用されるツール
#Pyttsx3 - テキストを音声に変換し、速度、頻度、音声を制御しますimport pyttsx3 import requests from bs4 import BeautifulSoup engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') newVoiceRate = 130 ## Reduce The Speech Rate engine.setProperty('rate',newVoiceRate) engine.setProperty('voice', voices[1].id) def speak(audio): engine.say(audio) engine.runAndWait() text = str(input("Paste articlen")) res = requests.get(text) soup = BeautifulSoup(res.text,'html.parser') articles = [] for i in range(len(soup.select('.p'))): article = soup.select('.p')[i].getText().strip() articles.append(article) text = " ".join(articles) speak(text) # engine.save_to_file(text, 'test.mp3') ## If you want to save the speech as a audio file engine.runAndWait()2. スケッチを自動的に生成します
このスクリプトはカラー写真を鉛筆スケッチに変換することができ、ポートレートや風景に良い効果をもたらします。 また、ワンクリックで生成するには数行のコードしか必要とせず、バッチ操作に適しており、非常に高速です。 必要なサードパーティ ライブラリ: Opencv - Python インターフェイスを使用して、多様な画像およびビデオ処理を実現できるコンピューター ビジョン ツール
""" Photo Sketching Using Python """ import cv2 img = cv2.imread("elon.jpg") ## Image to Gray Image gray_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ## Gray Image to Inverted Gray Image inverted_gray_image = 255-gray_image ## Blurring The Inverted Gray Image blurred_inverted_gray_image = cv2.GaussianBlur(inverted_gray_image, (19,19),0) ## Inverting the blurred image inverted_blurred_image = 255-blurred_inverted_gray_image ### Preparing Photo sketching sketck = cv2.divide(gray_image, inverted_blurred_image,scale= 256.0) cv2.imshow("Original Image",img) cv2.imshow("Pencil Sketch", sketck) cv2.waitKey(0)
#3. 複数の電子メールを自動的に送信する
このスクリプトは、定期的に電子メールをバッチで送信するのに役立ちます。電子メールの内容と添付ファイルもカスタマイズおよび調整できるため、非常に実用的です。
電子メール クライアントと比較した場合、Python スクリプトの利点は、電子メール サービスをインテリジェントに、バッチで、高度なカスタマイズで展開できることです。
必要なサードパーティ ライブラリ:
Email - 電子メール メッセージの管理に使用されます
Smtlib - SMTP クライアント セッション オブジェクトを定義する SMTP サーバーに電子メールを送信します。インターネット上の SMTP または ESMTP リスニング プログラムを使用して任意のコンピュータに電子メールを送信できます
Pandas - データ分析およびクリーニング用ツール
import smtplib from email.message import EmailMessage import pandas as pd def send_email(remail, rsubject, rcontent): email = EmailMessage()## Creating a object for EmailMessage email['from'] = 'The Pythoneer Here'## Person who is sending email['to'] = remail## Whom we are sending email['subject'] = rsubject ## Subject of email email.set_content(rcontent) ## content of email with smtplib.SMTP(host='smtp.gmail.com',port=587)as smtp: smtp.ehlo() ## server object smtp.starttls() ## used to send data between server and client smtp.login("deltadelta371@gmail.com","delta@371") ## login id and password of gmail smtp.send_message(email)## Sending email print("email send to ",remail)## Printing success message if __name__ == '__main__': df = pd.read_excel('list.xlsx') length = len(df)+1 for index, item in df.iterrows(): email = item[0] subject = item[1] content = item[2] send_email(email,subject,content)
4. 自動化されたデータ探索
Data探索はデータ サイエンス プロジェクトの最初のステップであり、より深い価値をさらに分析するには、データの基本情報を理解する必要があります。
通常、データの探索には pandas や matplotlib などのツールを使用しますが、多くのコードを自分で記述する必要があるため、効率を向上させたい場合は Dtale が最適です。
Dtale は、1 行のコードで自動分析レポートを生成するのが特徴で、Flask バックエンドと React フロントエンドを組み合わせて、Pandas データ構造を簡単に表示および分析する方法を提供します。
Jupyter 上で Dtale を使用できます。
必要なサードパーティ ライブラリ:
Dtale - 分析レポートを自動的に生成
### Importing Seaborn Library For Some Datasets import seaborn as sns ### Printing Inbuilt Datasets of Seaborn Library print(sns.get_dataset_names()) ### Loading Titanic Dataset df=sns.load_dataset('titanic') ### Importing The Library import dtale #### Generating Quick Summary dtale.show(df)
#5 、自動デスクトッププロンプト
このスクリプトは、Windows デスクトップ通知を自動的にトリガーして、次のような重要な事項を促します。2 時間作業してきたので、休憩を取る時間です。
固定時間を設定できます。 10 分ごと、1 時間ごとなどのプロンプトを表示します。
使用したサードパーティ ライブラリ:
win10toast - デスクトップ通知を送信するツール
from win10toast import ToastNotifier import time toaster = ToastNotifier() header = input("What You Want Me To Remembern") text = input("Releated Messagen") time_min=float(input("In how many minutes?n")) time_min = time_min * 60 print("Setting up reminder..") time.sleep(2) print("all set!") time.sleep(time_min) toaster.show_toast(f"{header}", f"{text}", duration=10, threaded=True) while toaster.notification_active(): time.sleep(0.005)
概要
Python で実現できる自動化機能は非常に豊富なので、需要のあるシナリオで「怠惰」になれる場合は、試してみるとよいでしょう。
以上が便利で使いやすい 5 つの Python 自動化スクリプトの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

WebStorm Mac版
便利なJavaScript開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール
