Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Aug 19 16:25:46 2017
  4.  
  5. @author: Anwar Goulouh
  6. """
  7.  
  8. import requests
  9. from bs4 import BeautifulSoup
  10. from datetime import datetime
  11. from tkinter import *
  12.  
  13.  
  14. #Make Window
  15. root = Tk()
  16. root.geometry("612x417")
  17. root.title("Exchange Rates")
  18. root.resizable(0,0)
  19. root.configure(background='lightgrey')
  20. #End
  21.  
  22. amount = '1'
  23. cur1 = input('What Currency would you like to trade from? ')
  24. cur2 = input('What Currency would you like to trade to? ')
  25. cur1_1 = StringVar()
  26. cur2_1 = StringVar()
  27. #i = 0
  28.  
  29.  
  30. #Labels for textboxes
  31. lblfrmcur = Label(root, text="From Currency",font="Helvetica 10 bold", width=12, anchor='w')
  32. lblfrmcur.place(x=5,y=50)
  33.  
  34. lbltocur = Label(root, text="To Currency",font="Helvetica 10 bold", width=12, anchor='w')
  35. lbltocur.place(x=5,y=75)
  36. #End
  37.  
  38. #Textboxes for user input
  39. txtcur1 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur1_1)
  40. txtcur1.place(x=110, y=50)
  41. txtcur2 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur2_1)
  42. txtcur2.place(x=110, y=75)
  43. #End
  44.  
  45. #Buttons
  46. btnConvert = Button(root, text="Get Exchange Rates",font="Helvetica 11 bold",bg="white",command=results)
  47. btnConvert.place(x=5,y=102)
  48. #End
  49.  
  50. def results():
  51. t = datetime.utcnow()
  52. url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur1 + "&To=" + cur2
  53. url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur2_1 + "&To=" + cur1_1
  54.  
  55.  
  56. html_code1 = requests.get(url1).text
  57. html_code2 = requests.get(url2).text
  58.  
  59. soup1 = BeautifulSoup(html_code1, 'html.parser')
  60. soup2 = BeautifulSoup(html_code2, 'html.parser')
  61.  
  62. # i = i + 1
  63.  
  64. rate1 = soup1.find('span', {'class', 'uccResultAmount'})
  65. rate2 = soup2.find('span', {'class', 'uccResultAmount'})
  66.  
  67. print ('#',i, t,'\n', cur1,'-',cur2, rate1.contents[0], cur2,'-',cur1, rate2.contents[0], '\n')
  68. print (cur1_1, cur2_1)
  69.  
  70.  
  71. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement