Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Build an Application for Screen Rotation Using Python
Next article icon

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:

Installation:

pip install bs4

Installation:

pip install requests

Step-by-step Approach:

Implementation:

Step 1: Import all the modules required.

Python3
# Import required modulesimportrequestsfrombs4importBeautifulSoup

 
Step 2: Create a URL get function 

Python3
# Function to extract html datadefgetdata(url):r=requests.get(url)returnr.text

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

The URL used here ishttps://finance.yahoo.com/quote/usdinr=X?ltr=1 

Python3
# Extract and converthtmldata=getdata("https://finance.yahoo.com/quote/usdinr=X?ltr=1")soup=BeautifulSoup(htmldata,'html.parser')result=(soup.find_all("div",class_="D(ib) Va(m) Maw(65%) Ov(h)")

Output:

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

Python3
mydatastr=''# Filter converted datafortableinsoup.find_all("div",class_="D(ib) Va(m) Maw(65%) Ov(h)"):mydatastr+=table.get_text()# Display outputprint(mydatastr)

Output:

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

Below is the complete program implemented usingtkinter module.

Python
# Import required modulesfromtkinterimport*importrequestsfrombs4importBeautifulSoup# user defined function# to extract currency detailsdefgetdata(url):r=requests.get(url)returnr.text# Function to compute and display currency detailsdefget_info():try:htmldata=getdata("https://finance.yahoo.com/quote/usdinr=X?ltr=1")soup=BeautifulSoup(htmldata,'html.parser')mydatastr=''fortableinsoup.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("-")rate.set(temp[0])inc.set(temp[1])per_rate.set(list_data[1])time.set(list_data[3])result.set("success")except:result.set("Opps! something wrong")# Driver Code# Create tkinter objectmaster=Tk()# Set background colormaster.configure(bg='light grey')# Variable Classes in tkinterresult=StringVar()rate=StringVar()per_rate=StringVar()time=StringVar()inc=StringVar()# Creating label for each informationLabel(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 variableLabel(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 buttonb=Button(master,text="Show",command=get_info,bg="Blue").grid(row=0)mainloop()

Output:


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp