Skip to content
Related Articles

Related Articles

Improve Article

Application to get live USD/INR rate Using Python

  • Last Updated : 30 Sep, 2021
Geek Week

In this article, we are going to write a python scripts to get live information of USD/INR rate and bind with it GUI application.

Modules Required:

  • bs4: Beautiful Soup is a Python library for pulling data out of HTML and XML files.


pip install bs4
  • requests: This module allows you to send HTTP/1.1 requests very easily.


pip install requests

Step-by-step Approach:

  • Extract data from the given URL. Copy the URL, after selecting the desired location.
  • Scrape the data with the help of requests and the Beautiful Soup module.
  • Convert that data into HTML code.
  • Find the required details and filter them.


Step 1: Import all the modules required.


# Import required modules
import requests
from bs4 import BeautifulSoup

Step 2: Create a URL get function 


# Function to extract html data
def getdata(url):
    return r.text

Step 3: Now pass the URL into the getdata() function and convert that data(currency details) into HTML code.

The URL used here is 


# Extract and convert
soup = BeautifulSoup(htmldata, 'html.parser')
result = (soup.find_all("div", class_="D(ib) Va(m) Maw(65%) Ov(h)")


Step 4: Filter the currency details and quality(increment/decrement) according to the given data.


mydatastr = ''
# Filter converted data
for table in soup.find_all("div", class_="D(ib) Va(m) Maw(65%) Ov(h)"):
    mydatastr += table.get_text()
# Display output


'73.2610-0.2790 (-0.38%)As of  3:30PM BST. Market open.'

Below is the complete program implemented using tkinter module.


# Import required modules
from tkinter import *
import requests
from bs4 import BeautifulSoup
# user defined function
# to extract currency details
def getdata(url):
    r = requests.get(url)
    return r.text
# Function to compute and display currency detalis
def get_info():
        htmldata = getdata("")
        soup = BeautifulSoup(htmldata, 'html.parser')
        mydatastr = ''
        for table in soup.find_all("div", class_="D(ib) Va(m) Maw(65%) Ov(h)"):
            mydatastr += table.get_text()
        list_data = mydatastr.split()
        temp = list_data[0].split("-")
        result.set("Opps! someting wrong")
# Driver Code       
# Create tkinter object
master = Tk()
# Set background color
master.configure(bg='light grey')
# Variable Classes in tkinter
result = StringVar()
rate = StringVar()
per_rate = StringVar()
time = StringVar()
inc = StringVar()
# Creating label for each information
Label(master, text="Status :", bg="light grey").grid(row=2, sticky=W)
Label(master, text="Current rate of INR :",
      bg="light grey").grid(row=3, sticky=W)
Label(master, text="Increase/decrease by :",
      bg="light grey").grid(row=4, sticky=W)
Label(master, text="Rate change :", bg="light grey").grid(row=5, sticky=W)
Label(master, text="Rate of time :", bg="light grey").grid(row=6, sticky=W)
# Creating lebel for class variable
Label(master, text="", textvariable=result,
      bg="light grey").grid(row=2, column=1, sticky=W)
Label(master, text="", textvariable=rate,
      bg="light grey").grid(row=3, column=1, sticky=W)
Label(master, text="", textvariable=inc, bg="light grey").grid(
    row=4, column=1, sticky=W)
Label(master, text="", textvariable=per_rate,
      bg="light grey").grid(row=5, column=1, sticky=W)
Label(master, text="", textvariable=time,
      bg="light grey").grid(row=6, column=1, sticky=W)
# Create submit button
b = Button(master, text="Show", command=get_info, bg="Blue").grid(row=0)


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :