-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptocreeper.py
executable file
·89 lines (67 loc) · 2.02 KB
/
cryptocreeper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
from tkinter import *
import json
import requests
import webbrowser
url = "https://api.coincap.io/v2/assets"
try:
req = requests.get(url, verify=False)
x = json.loads(req.text)
except:
print("exit")
exit(0)
def callback():
showsyms()
webbrowser.open_new_tab(asseturl)
def showsyms():
global values
values = []
for y in range(len(x['data'])):
values.append(x['data'][y]['symbol'])
values = sorted(values)
return values
options = showsyms()
def makeusd(cash):
x = str(cash).startswith("0.00")
if x == True:
usd = f"${cash}"
else:
usd = '${:,.2f}'.format(float(cash))
return(usd)
def update(txt):
myLabel.configure(text=txt)
def showsyms():
global asseturl
try:
req = requests.get(url, verify=False)
x = json.loads(req.text)
for y in range(len(x['data'])):
if x['data'][y]['symbol'] == clicked.get():
name = x['data'][y]['name']
symbol = x['data'][y]['symbol']
asseturl = f"https://www.blockchain.com/explorer/assets/{symbol}"
priceUsd = float(x['data'][y]['priceUsd'])
changePercent24Hr = str(round(float(x['data'][y]['changePercent24Hr']), 2))
if changePercent24Hr.startswith('-'):
p = f"Down {changePercent24Hr}% in the last 24 hours"
else:
p = f"Up {changePercent24Hr}% in the last 24 hours"
price = makeusd(priceUsd)
update(f"\n{name}: {price}\n\n{p}\n")
except:
exit(1)
root = Tk()
root.title("Crypto Creeper")
root.geometry("250x200")
myLabel = Label(root, text='\n\nPick a Crypto\n\n')
myLabel.pack()
clicked = StringVar()
if 'BTC' in values:
clicked.set('BTC')
else:
clicked.set(values[0])
drop = OptionMenu(root, clicked, *options)
drop.pack()
Button(root, text=" Update ", command=showsyms).pack()
Button(root, text="Explorer", command=callback).pack()
root.mainloop()