みなさん、こんにちは。私の名前はジャックポップです。
このジレンマに頻繁に遭遇しますか?親戚や友人が私たちの家に来たとき、彼らはWiFiパスワードを要求し、それから彼らは箱を通り抜けて振り返ったが、彼らはそれを見つけることができなかった。
今日は、Pythonのあまり知られていない操作をいくつか紹介します。
これらの操作はまばゆいばかりではありませんが、本当に実用的です!
1.WiFiパスワードを表示する
Wi-Fiパスワードを忘れがちですが、親戚や友人が家に来てWi-Fiパスワードを尋ねると、どこから始めればよいのかわかりません。
これは、すべてのデバイスとそのパスワードを一覧表示できるトリックです。
import subprocess #import required library
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n') #store profiles data in "data" variable
profiles = [i.split(":")[1][1:-1] for i in data if"All User Profile"in i] #store the profile by converting them to list
for i in profiles:
# running the command to check passwords
results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')
# storing passwords after converting them to list
results = [b.split(":")[1][1:-1] for b in results if"Key Content"in b]
try:
print ("{:<30}| {:<}".format(i, results[0]))
except IndexError:
print ("{:<30}| {:<}".format(i, ""))
2.ビデオからGIFへ
近年、GIFがブームになっています。人気のソーシャルメディアプラットフォームのほとんどは、ユーザーにさまざまなGIFを提供して、より意味のあるわかりやすい方法で自分の考えを表現します。
多くの学生がビデオをGIFに変換するのに多大な労力を費やし、その過程で多くの落とし穴を踏みました。
Pythonでは、数行の短いコードです。
インストール
pip install moviepy
コード
from moviepy.editor import VideoFileClip
clip = VideoFileClip("video_file.mp4") # Enter your video's path
clip.write_gif("gif_file.gif", fps = 10)
3.デスクトップリマインダー
プロジェクトなどに取り組んでいると、重要なことを忘れてしまうことがあり、システムに簡単な通知が表示されるので覚えておくことができます。
Pythonの助けを借りて、パーソナライズされた通知を作成し、特定の時間にそれらをスケジュールすることができます。
インストール
pip install win10toast, schedule
コード
import win10toast
toaster = win10toast.ToastNotifier()
import schedule
import time
def job():
toaster.show_toast('提醒', "到吃饭时间了!", duration = 15)
schedule.every().hour.do(job) #scheduling for every hour; you can even change the scheduled time with schedule library
whileTrue:
schedule.run_pending()
time.sleep(1)
4.ショートカットキーをカスタマイズします
時々、私たちは仕事で頻繁にいくつかの単語を入力する必要があります。キーボードを自動化し、これらの頻繁に使用される単語を略語のみを使用して書くことができたら、楽しいと思いませんか?
そうです、Pythonでそれを可能にすることができます。
インストール
pip install keyboard
コード
import keyboard
#press sb and space immediately(otherwise the trick wont work)
keyboard.add_abbreviation('ex', '我是一条测试数据!') #provide abbreviation and the original word here
# Block forever, like `while True`.
keyboard.wait()
次に、任意の位置にex
プラスを入力空格
して、対応する文をすばやく完成させます。
5.PDFへのテキスト
オンラインで入手できるメモや本の一部がPDF形式であることは誰もが知っています。
これは、PDFがプラットフォームやデバイスに関係なく同じ方法でコンテンツを保存できるためです。
したがって、テキストファイルがある場合は、Pythonライブラリfpdfを使用してPDFファイルに変換できます。
pip install fpdf
from fpdf import FPDF
pdf = FPDF()
pdf.add_page() # Add a page
pdf.set_font("Arial", size = 15) # set style and size of font
f = open("game_notes.txt", "r") # open the text file in read mode
# insert the texts in pdf
for x in f:
pdf.cell(50,5, txt = x, ln = 1, align = 'C')
#pdf.output("path where you want to store pdf file\\file_name.pdf")
pdf.output("game_notes.pdf")
6.QRコードを生成します
日常生活でQRコードをよく目にしますが、QRコードはユーザーの時間を大幅に節約します。
Pythonライブラリqrcodeを使用して、Webサイトまたはプロファイルに固有のQRコードを作成することもできます。
インストール
pip install qrcode
コード
#import the library
import qrcode
#link to the website
input_data = "https://car-price-prediction-project.herokuapp.com/"
#Creating object
#version: defines size of image from integer(1 to 40), box_size = size of each box in pixels, border = thickness of the border.
qr = qrcode.QRCode(version=1,box_size=10,border=5)
#add_date : pass the input text
qr.add_data(input_data)
#converting into image
qr.make(fit=True)
#specify the foreground and background color for the img
img = qr.make_image(fill='black', back_color='white')
#store the image
img.save('qrcode_img.png')
7.翻訳
私たちは多言語の世界に住んでいます。
したがって、さまざまな言語を理解するには、言語翻訳者が必要です。
PythonライブラリTranslatorを使用して、独自の言語トランスレータを作成できます。
インストール
pip install translate
コード
#import the library
from translate import Translator
#specifying the language
translator = Translator(to_lang="Hindi")
#typing the message
translation = translator.translate('Hello!!! Welcome to my class')
#print the translated message
print(translation)
8.Google検索
プログラミングが忙しくて、ブラウザを開いて必要な答えを検索するのが面倒な場合があります。
しかし、Googleのこの素晴らしいPythonライブラリでは、ブラウザを手動で開いてクエリを検索しなくても、クエリを検索するために3行のコードを記述するだけで済みます。
インストール
pip install google
コード
#import library
from googlesearch import search
#write your query
query = "best course for python"
# displaying 10 results from the search
for i in search(query, tld="co.in", num=10, stop=10, pause=2):
print(i)
#you will notice the 10 search results(website links) in the output.
9.音声を抽出する
場合によっては、mp4ファイルがありますが、別のビデオのオーディオを使用してビデオを作成する場合のように、オーディオのみが必要です。
同じオーディオファイルを取得するのに十分な試みをしましたが、失敗しました。
この問題は、Pythonライブラリのmoviepyで簡単に解決できます。
インストール
pip install moviepy
コード
#import library
import moviepy.editor as mp
#specify the mp4 file here(mention the file path if it is in different directory)
clip = mp.VideoFileClip('video.mp4')
#specify the name for mp3 extracted
clip.audio.write_audiofile('Audio.mp3')
#you will notice mp3 file will be created at the specified location.
10.ショートリンクを生成する
私はよくあらゆる種類のリンクを扱います、そして長いURLは私の心を混乱させます!
その結果、さまざまなショートリンク生成ツールがあります。
ただし、ほとんどの使用は面倒です。
Pythonライブラリpyshortenersを使用して、独自のショートリンクジェネレーターを作成できます。
インストール
pip install pyshorteners
コード
#import library
import pyshorteners
#creating object
s=pyshorteners.Shortener()
#type the url
url = "type the youtube link here"
#print the shortend url
print(s.tinyurl.short(url))
これを読んだ後、作業に関連する機械学習とデータ分析のプロジェクト開発を完了することに加えて、Pythonは作業効率を大幅に向上させることができる多くの非常に興味深い操作も完了することができることがわかります。
この記事はいくつかのアイデアを引き付けるためのものです。もっと面白いPythonゲームプレイを見つけていただければ幸いです。
最後に、Java、アルゴリズム、Python、SQLなどのさまざまな分野と方向性をカバーする、アルゴリズムとプログラミングスキルを実践するための非常に優れたプラットフォームをお勧めします。質問バンクは豊富で完全に無料です。