9 Simple and Useful Task Using Python

Posted on

1. Google Search with Python

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);
#you will notice the 10 search results(website links) in the output.

2. Downloading instagram Posts and Profile Picture

pip install instaloader

#to doenload all the posts of a profile
import instaloader
#creating object
d = instaloader.instaloader()
#specifying 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 download

3. Extracting audio from the video files

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.

4. URL Shortener

pip install pyshorteners
#import library 
import pyshorteners 
#creating object 
#type the url 
url = "type the youtube link here" 
#print the shortend url 

5. Image to PDF Convertor

pip install img2pdf

#mport 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")]))

6. Plagiarism detector

pip install 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 to them here 
		similarity_ratio = SequenceMatcher(None, filel_data, file2_data).ratio() 
		#print the plagiarsim ratio 
		print( similarity_ratio)

7. Language 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 TheStarkArmy Network') 
#print the translated message 

8. QR code generator

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 
#converting into Image 
#specify the foreground and background color for the img 
img = qr.make_image(fill='black', back_color='white') 
#store the image 

9. Download Youtube videos

pip install pytube
#lmport 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 
#show the message when download is completed 
print("Download completed!!")

Leave a Reply

Your email address will not be published. Required fields are marked *