9 Amazing Things To Do With Python

Hello, buddies! We love python, right? So today we’re going to see some amazing things that can be done with python(you may not know them). Interesting? Let’s start!

1. Google Search with Python

Sometimes we get so much into programming th…


This content originally appeared on DEV Community and was authored by Mr. Unity Buddy

Hello, buddies! We love python, right? So today we're going to see some amazing things that can be done with python(you may not know them). Interesting? Let's start!

1. Google Search with Python

Sometimes we get so much into programming that we feel lazy enough to open the browser and search our queries. But with the amazing python library google, we can search our queries by just writing 3 lines of code without manually opening the browser and searching our query on it.

To install,

pip install google

Code,

#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.

2. Downloading Instagram Posts and profile picture

We all come across some wonderful posts on Instagram and want to save them offline on our devices. But the app provides posts to be saved online for later and not offline. This can be done with the amazing python library instaloader.

To install library,

pip install instaloader

Code,

#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

3. Extracting audio from the video files

There are certain situations when we have the mp4 file but we only need the audio from it. Like making a video with audio of another video. We struggle enough to get the same audio file, but we fail and unfortunately, we decide to choose the other music file. This problem is solved with the python library moviepy, as we can extract the audio from the video files through this.

To install library,

pip install moviepy

Code,

#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

Dealing with long URLs is a hectic task when you have to regularly work with them. There comes the idea of URL Shorteners(such as bit.ly and tinyurl). These services shorten the URL to below 50 characters. We can create our own URL shortener with the help of the python library pyshorteners.

To install library,

pip install pyshorteners

Code,

#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))

5. Image to PDF Convertor

Sometimes we have our notes or documents as photographs, and it becomes difficult to study in that manner. We might follow the wrong sequence and things become confusing and annoying. To solve this problem one idea is to collect all the images and then convert them into a pdf file. This can be done with the python library img2pdf.

To install library,

pip install img2pdf

Code,

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

6. Plagiarism detector

One of the most important factors for dealing with content writing is Plagiarism. It’s not even possible to check the files manually when they are in bundles. There comes the need for the Plagiarism detector tool. We can also create our own plagiarism detector with the help of the python library difflib. It can be used to check similarities between two or more files on a device.

To install library,

pip install difflib

Code,

#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) 

7. Language Translator

We live in a world of multilingual people. Therefore to understand each other’s language, we need a language translator, since we cannot learn these many languages. We can create our own language translator with the help of the python library Translator.

To install library,

pip install translate

Code,

#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. QR code generator

We see QR(Quick Response) code often in our day-to-day life. A very quick example is payment apps, where QR code saves a lot of user’s time. We can also create our unique QR code for website or profiles with the python library qrcode

To install library,

pip install qrcode

Code,

#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')

9. Download Youtube videos

We all see some of the useful content on youtube whether it be educational or for entertainment purposes. This platform doesn’t charge us and it’s available free to watch an unlimited wide variety of videos. The only problem arises when we want to download these videos for the future. Here is a cool python library pytube which supports downloading.

To install library,

pip install pytube

Code,

#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!!")

Or else, you can try this article's method by @Siddharth Chandra

So buddies, that's for now. Thanks for reading and Happy Coding!


This content originally appeared on DEV Community and was authored by Mr. Unity Buddy


Print Share Comment Cite Upload Translate Updates
APA

Mr. Unity Buddy | Sciencx (2021-08-11T15:15:08+00:00) 9 Amazing Things To Do With Python. Retrieved from https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/

MLA
" » 9 Amazing Things To Do With Python." Mr. Unity Buddy | Sciencx - Wednesday August 11, 2021, https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/
HARVARD
Mr. Unity Buddy | Sciencx Wednesday August 11, 2021 » 9 Amazing Things To Do With Python., viewed ,<https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/>
VANCOUVER
Mr. Unity Buddy | Sciencx - » 9 Amazing Things To Do With Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/
CHICAGO
" » 9 Amazing Things To Do With Python." Mr. Unity Buddy | Sciencx - Accessed . https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/
IEEE
" » 9 Amazing Things To Do With Python." Mr. Unity Buddy | Sciencx [Online]. Available: https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/. [Accessed: ]
rf:citation
» 9 Amazing Things To Do With Python | Mr. Unity Buddy | Sciencx | https://www.scien.cx/2021/08/11/9-amazing-things-to-do-with-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.