Python以其大量的预定义库而闻名,这节省了我们很多时间。在本文中,我们将通过一些稀有却很酷的库学习一些惊人的python hack。本文的主要目的是借助python学习(或自动化)一些基本知识。因此,让我们开始吧。
老规矩,需要打包好的软件关注小编,QQ群:721195303领取。
1.下载YouTube视频
我们所有人都在YouTube上看到了一些有用的内容,无论是出于教育目的还是出于娱乐目的。该平台不向我们收费,可以免费观看无限多的视频。唯一的问题出现在我们将来要下载这些视频时。这是一个很酷的python库“ pytube”,它支持下载。
要安装库:
pip安装pytube
代码:
#import the library
from pytube import YouTube
#ask user to type in the link
link = input("Enter the link of youtube video: ")
#creating an object
yt = YouTube(link)
#to get the highest resolution
ys = yt.streams.get_highest_resolution()
#show the message until downloading
print("Downloading...")
#specifying the location for this video
ys.download("Downloads\python")
#show the message when download is completed
print("Download completed!!")
2.自动化Whatsapp消息
毫无疑问,Whatsapp已成为Android用户最默认的应用程序。这个应用程序使我们可以在世界任何角落的任何地方发送消息。除了其所有令人惊奇的功能之外,在特定时间安排我们的消息将是最酷的事情。这可以通过python库“ pywhatkit”来完成
要安装库:
pip安装pywhatkit
代码:
#you should be logged in with whatsapp web in your default browser.
#import the library
import pywhatkit
#pywhatkit.sendwhatmsg(reciever's number, message, hour(scheduled) in 24 hr format, minute(scheduled) )
pywhatkit.sendwhatmsg('+91 0000000000','hye, this is automated message',14,22)
#message will be sent on sender's number at the scheduled time that is (2:22 pm)
3.使用Python的Google搜索
有时,我们对编程的投入如此之大,以至于觉得自己懒得打开浏览器并搜索查询。但是有了神奇的python库“ google”,我们只需编写3行代码即可搜索我们的查询,而无需手动打开浏览器并在其上搜索查询。
要安装库:
pip安装谷歌
代码:
#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.
4.下载Instagram帖子和个人资料图片
我们都在Instagram上遇到了一些很棒的帖子,并希望将它们离线保存在我们的设备上。但是该应用程序提供的帖子可以在线保存,以备日后使用,而不是离线。这可以通过令人惊叹的python库“ instaloader”来完成。
要安装库:
pip安装instaloader
代码:
#to download all the posts of a profile
import instaloader
#creating object
d = instaloader.Instaloader()
#sepcifying the profile name
profile_Name = 'enter the instagram_handle'
#do profile_pic_only = True, to download the profile picture
d.download_profile(profile_Name, profile_pic_only = False)
#you will notice a folder of this profile's name, under which all the posts will get downloaded
5.从视频文件中提取音频
在某些情况下,我们拥有mp4文件,但我们只需要其中的音频即可。我们已经竭尽全力以获取相同的音频文件,但失败了,很不幸,我们决定选择其他音乐文件。这个问题可以通过python库“ moviepy”解决,因为我们可以通过该库从视频文件中提取音频。
要安装库:
pip安装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.
6. URL缩短器
当必须定期使用长URL时,处理长URL是一项繁琐的任务。URL缩短器(例如bit.ly和tinyurl)的想法来了。这些服务将URL缩短到50个字符以下。我们可以在python库“ pyshorteners”的帮助下创建自己的URL缩短器。
要安装库:
pip安装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))
7.图像到PDF转换器
有时我们的笔记或文件是照片,因此很难以这种方式进行研究。我们可能遵循错误的顺序,事情变得令人困惑和烦恼。为了解决这个问题,一个想法是收集所有图像,然后将它们转换为pdf文件。这可以通过python库“ img2pdf”来完成。
要安装库:
pip安装img2pdf
代码:
#import libraries
import os
import img2pdf
#specify the name for pdf file
with open("converted.pdf", "wb") as f:
#collect all the images in a single folder and specify its location
f.write(img2pdf.convert([i for i in os.listdir(files\images) if i.endswith(".jpg")]))
8.抄袭探测器
处理内容写作的最重要因素之一是Pla窃。捆绑在一起时,甚至无法手动检查文件。这就需要the窃检测工具。我们还可以借助python库“ difflib”创建自己的窃检测器。它可用于检查设备上两个或多个文件之间的相似性。
代码:
#import the required library
from difflib import SequenceMatcher
#opening two text files
with open('file_one.txt') as file_1, open('file_two.txt') as file_2:
#read the files in another variables
file1_data = file_1.read()
file2_data = file_2.read()
#since we have taken two files for detecting plagiarism, we mention two them here
similarity_ratio = SequenceMatcher(None,file1_data,file2_data).ratio()
#print the plagiarsim ratio
print(similarity_ratio)
9.语言翻译器
我们生活在一个使用多种语言的人的世界中。因此,要了解彼此的语言,我们需要语言翻译器,因为我们无法学习许多语言。我们可以借助python库“ Translator”创建自己的语言翻译器。
要安装库:
pip安装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)
10. QR码生成器
在我们的日常生活中,我们经常看到QR(快速响应)代码。一个非常快速的示例是支付应用程序,其中的QR码可节省大量用户的时间。我们还可以使用python库“ qrcode”为网站或个人资料创建唯一的QR码
要安装库:
PIP安装QR码
代码:
#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')