Open In App
Related Articles

Application to get live USD/INR rate Using Python

Improve Article
Save Article
Like Article

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 details
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! something 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 label 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)


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 10 Jan, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials