-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_conky.py
More file actions
88 lines (71 loc) · 2.6 KB
/
Copy pathpython_conky.py
File metadata and controls
88 lines (71 loc) · 2.6 KB
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
"""
This File creates a widget on your desktop (on the bottom) with curves for Ethereum and Bitcoin last buy for the last 5 minutes or so.
The variables in the beginning define the number of values stored and the time frame
To avoid using to much internet in the beginning, it initializes with a flat curves and starts recovering data.
"""
total_time = 300
#number of points to store (ajust if you wish to use less RAM) and length of the X axis
time_interval = 1 #in seconds
your_currency = "USD" #you can put EUR for euro or other for any currency supported by kraken
crypto_one = "XBT"
crypto_two = "ETH"
import json
import requests
import tkinter as tk
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.animation as animation
from matplotlib import style
# URL: https://api.kraken.com/0/public/Ticker
def krak(ticker):
uri = "https://api.kraken.com/0/public/Ticker"
blah = uri + "?pair=" + ticker
r = requests.get(blah)
json_data = r.text
fj = json.loads(json_data)
fuu = fj["result"][ticker]["c"]
for price in fuu:
btc = fuu[0]
size = fuu[1]
return btc
x = [i*time_interval for i in range(total_time)]
initial = krak("X" + crypto_one + "Z" + your_currency)
XBT = [initial for i in range(total_time)]
initial = krak("X" + crypto_two + "Z" + your_currency)
ETH = [initial for i in range(total_time)]
def get_back_values(L,cur):
try :
L.append(krak(cur))
L.pop(0)
except :
print("Error in data maybe internet is down ?")
def update_graph(dt):
get_back_values(XBT,"X" + crypto_one + "Z" + your_currency)
get_back_values(ETH,"X" + crypto_two + "Z" + your_currency)
ax1.clear()
ax2.clear()
ax2.set_xlabel('Time (seconds)')
ax2.yaxis.label.set_color('black')
ax1.set_ylabel('XBT prices (' +your_currency+")" , color='g')
ax2.set_ylabel('ETH prices (' +your_currency+")", color='r')
ax1.plot(x, XBT, 'g')
ax2.plot(x, ETH, 'r')
app = tk.Tk()
app.wm_title("Cryptocurrencies")
app.wm_attributes('-type',"desktop")
app.geometry("+250+780")
app.wm_attributes("-alpha", 0.35)
style.use("dark_background")
fig = Figure(figsize=(8, 3), dpi=112)
fig.patch.set_facecolor('None')
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
ax2.set_xlabel('Time (seconds)')
ax1.set_ylabel('XBT prices', color='g')
ax2.set_ylabel('ETH prices', color='r')
fig.tight_layout()
graph = FigureCanvasTkAgg(fig, master=app)
canvas = graph.get_tk_widget()
canvas.grid(row=0, column=0)
ani = animation.FuncAnimation(fig, update_graph, interval=int(time_interval*1000))
app.mainloop()