Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # requirements.txt
- """
- requests_html
- """
- # currency_converter.py
- from requests_html import HTMLSession
- def convert(amount=1, _from='ars', to='usd'):
- url = f'https://www.google.com/search?q={amount}+{_from}+to+{to}'
- session = HTMLSession()
- response = session.get(url)
- html = response.html
- result_selector = "#knowledge-currency__updatable-data-column > div.b1hJbf > div.dDoNo.vk_bk.gsrt > span.DFlfde.SwHCTb"
- result = html.find(result_selector)[0]
- return result.text
- # currency_converterUI.py
- from tkinter import Frame, Tk, StringVar, DoubleVar
- from tkinter import ttk
- from currency_converter import convert
- class ConverterUI(Frame):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.currencies = ('ars', 'usd', 'mxn', 'eur',) # Default list of currency 'symbols'
- self.master.title('Currency Converter? Lol - by David Emanuel Sandoval')
- self.make_widgets()
- def make_widgets(self):
- # setting up all the widgets
- self._from_lbl = ttk.Label(self, text='De:')
- self.to_lbl = ttk.Label(self, text='a:')
- # Variables for the comboboxes
- self._from = StringVar()
- self.to = StringVar()
- self._from_combo = ttk.Combobox(self, values=self.currencies, textvariable=self._from)
- self.to_combo = ttk.Combobox(self, values=self.currencies, textvariable=self.to)
- # second row widgets
- self.amount_lbl = ttk.Label(self, text='Cantidad:')
- self.result = StringVar()
- self.result.set('Recalculando... :-)')
- self.amount = DoubleVar()
- self.amount.set(1)
- self.amount_spin = ttk.Spinbox(self, from_=0, to=9999999, textvariable=self.amount)
- self.convert_btn = ttk.Button(self, text='Calcular', command=self.convert)
- self.result_lbl = ttk.Label(self, textvariable=self.result)
- # placing
- self._from_lbl.grid(row=0, column=0)
- self.to_lbl.grid(row=0, column=2)
- self._from_combo.grid(row=0, column=1)
- self.to_combo.grid(row=0, column=3)
- self.amount_lbl.grid(row=1, column=0)
- self.amount_spin.grid(row=1, column=1)
- self.convert_btn.grid(row=1, column=2)
- self.result_lbl.grid(row=1, column=3)
- def convert(self):
- amount = self.amount.get()
- _from = self._from.get()
- to = self.to.get()
- result = convert(amount, _from, to)
- result = f'Resultado: {result}'
- self.result.set(result)
- def main():
- root = Tk()
- w = ConverterUI()
- w.pack()
- root.mainloop()
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment