Skip to content

Commit

Permalink
feat Python Python Tkinter Bitcoin Price Web Scraper With BeautifulSo…
Browse files Browse the repository at this point in the history
…up update 2

Python Python Tkinter Bitcoin Price Web Scraper With BeautifulSoup update 3

Resolves: #
See also: #
  • Loading branch information
brian-emarquez committed Jan 20, 2021
1 parent 8465948 commit 53252ef
Showing 1 changed file with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 53252ef

Please sign in to comment.