Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 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. import tkinter as tk
  12. #from tkinter import *
  13.  
  14.  
  15. #Make Window
  16. root = tk.Tk()
  17. root.geometry("612x417")
  18. root.title("Exchange Rates")
  19. root.resizable(0,0)
  20. root.configure(background='lightgrey')
  21. #End
  22.  
  23.  
  24. amountex = '1'
  25.  
  26.  
  27. def continuousUpdate():
  28. while amount == '0':
  29. results()
  30.  
  31.  
  32.  
  33. def results():
  34. # while amount == '0':
  35. t = datetime.utcnow()
  36. url1 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur1 + "&To=" + cur2
  37. url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amountex + "&From=" + cur2_1.get() + "&To=" + cur1_1.get()
  38.  
  39.  
  40. html_code1 = requests.get(url1).text
  41. html_code2 = requests.get(url2).text
  42.  
  43. soup1 = BeautifulSoup(html_code1, 'html.parser')
  44. soup2 = BeautifulSoup(html_code2, 'html.parser')
  45.  
  46. rate1 = soup1.find('span', {'class', 'uccResultAmount'})
  47. rate2 = soup2.find('span', {'class', 'uccResultAmount'})
  48.  
  49. lblfrmex_text.set(rate1.contents[0])
  50. lbltoex_text.set(rate2.contents[0])
  51. lbldatetime_text.set(t)
  52.  
  53.  
  54.  
  55. #LABELS
  56. #Label for current datetime of exchange rates
  57. lbltime = tk.Label(root, text="ExRate Datetime",font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=5,y=25)
  58. #Label datetime update
  59. lbldatetime_text = tk.StringVar()
  60. lbldatetime = tk.Label(root, textvariable=lbldatetime_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=25)
  61.  
  62.  
  63.  
  64. #Label for from textbox
  65. lblfrmcur = tk.Label(root, text="From Currency",font="Helvetica 10 bold", width=12, anchor='w', background='lightgrey').place(x=5,y=50)
  66.  
  67. #Label for from currency exrate
  68. lblfrmex_text = tk.StringVar()
  69. lblfrmex = tk.Label(root, textvariable=lblfrmex_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=50)
  70.  
  71. #Labels for to textbox
  72. lbltocur = tk.Label(root, text="To Currency",font="Helvetica 10 bold", width=12, anchor='w', background='lightgrey').place(x=5,y=75)
  73.  
  74. #Label for to currency exrate
  75. lbltoex_text = tk.StringVar()
  76. lbltoex = tk.Label(root, textvariable=lbltoex_text,font="Helvetica 10 bold", anchor='w', background='lightgrey').place(x=180,y=75)
  77.  
  78. #End
  79.  
  80.  
  81. #Textboxes for user input
  82. cur1_1 = tk.StringVar()
  83. txtcur1 = tk.Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur1_1).place(x=110, y=50)
  84.  
  85. cur2_1 = tk.StringVar()
  86. txtcur2 = tk.Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur2_1).place(x=110, y=75)
  87.  
  88. #End
  89.  
  90.  
  91. #Buttons
  92. btnConvert = tk.Button(root, text="Get Exchange Rates",font="Helvetica 11 bold",bg="white",command=results).place(x=5,y=102)
  93. #End
  94.  
  95.  
  96.  
  97. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement