Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Sat Aug 19 16:25:46 2017
- @author: Anwar Goulouh
- """
- import requests
- from bs4 import BeautifulSoup
- from datetime import datetime
- from tkinter import *
- #Make Window
- root = Tk()
- root.geometry("612x417")
- root.title("Exchange Rates")
- root.resizable(0,0)
- root.configure(background='lightgrey')
- #End
- amount = '1'
- cur1 = input('What Currency would you like to trade from? ')
- cur2 = input('What Currency would you like to trade to? ')
- cur1_1 = StringVar()
- cur2_1 = StringVar()
- #i = 0
- #Labels for textboxes
- lblfrmcur = Label(root, text="From Currency",font="Helvetica 10 bold", width=12, anchor='w')
- lblfrmcur.place(x=5,y=50)
- lbltocur = Label(root, text="To Currency",font="Helvetica 10 bold", width=12, anchor='w')
- lbltocur.place(x=5,y=75)
- #End
- #Textboxes for user input
- txtcur1 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur1_1)
- txtcur1.place(x=110, y=50)
- txtcur2 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur2_1)
- txtcur2.place(x=110, y=75)
- #End
- #Buttons
- btnConvert = Button(root, text="Get Exchange Rates",font="Helvetica 11 bold",bg="white",command=results)
- btnConvert.place(x=5,y=102)
- #End
- def results():
- t = datetime.utcnow()
- url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur1 + "&To=" + cur2
- url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur2_1 + "&To=" + cur1_1
- html_code1 = requests.get(url1).text
- html_code2 = requests.get(url2).text
- soup1 = BeautifulSoup(html_code1, 'html.parser')
- soup2 = BeautifulSoup(html_code2, 'html.parser')
- # i = i + 1
- rate1 = soup1.find('span', {'class', 'uccResultAmount'})
- rate2 = soup2.find('span', {'class', 'uccResultAmount'})
- print ('#',i, t,'\n', cur1,'-',cur2, rate1.contents[0], cur2,'-',cur1, rate2.contents[0], '\n')
- print (cur1_1, cur2_1)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement