diff --git a/Python Tkinter Bitcoin Price Web Scraper With BeautifulSoup/bitcoinPriceWebScrapeWithBeautifulSoup.py b/Python Tkinter Bitcoin Price Web Scraper With BeautifulSoup/bitcoinPriceWebScrapeWithBeautifulSoup.py index 4fbecd5f..da6757d3 100644 --- a/Python Tkinter Bitcoin Price Web Scraper With BeautifulSoup/bitcoinPriceWebScrapeWithBeautifulSoup.py +++ b/Python Tkinter Bitcoin Price Web Scraper With BeautifulSoup/bitcoinPriceWebScrapeWithBeautifulSoup.py @@ -18,6 +18,10 @@ global previous previous = False +# Get Current Time +now = datetime.now() +current_time = now.strftime("%I:%M:%S %p") + # Create a Frame my_frame = Frame(root, bg="black") my_frame.pack(pady=20) @@ -45,15 +49,53 @@ # Grab the bitcoin Price def Update(): - global previous - page = urllib.request.urlopen("https://www.coindesk.com/price/bitcoin") - # Grab bitcoin Prince + page = urllib.request.urlopen("https://www.coindesk.com/price/bitcoin").read() + html = BeautifulSoup(page, 'html.parser') + price_large = html.find(class_="price-large") + print(price_large) + # convert to string so we can slice + price_large1 = str(price_large) + + # Grab a slice that contains the price + price_large2 = price_large1[54:63] + + # Update our bitcoin label + bit_label.config(text=f'${price_large2}') # Set timer to 1 minute root.after(30000, Update) + # Get Current Time + now = datetime.now() + current_time = now.strftime("%I:%M:%S %p") + + # Determine Price Change + # grab current Prince + current = price_large2 + + # remove the coma + current =current.replace(',', '') + + if previous: + if float(previous) > float (current): + latest_price.config(text=f'Price Down'{float(previous)}, fg="grey") + + + else: + previous = current + latest_price.config(text="Price Unchange", fg="grey") + +# Create status bar +status_bar = Label(root, text=f'Last Updated{current_time} ', + bd=0, + anchor=E, + bg="black", + fg="grey") + +status_bar.pack(fill=X, side=BOTTOM, ipady=2) + # On program start Update() root.mainloop() \ No newline at end of file