-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhivebar.py
54 lines (41 loc) · 1.66 KB
/
hivebar.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
import rumps
import requests
VERSION = "0.0.1"
ABOUT_TEXT = "Version: %s. \n\nPrice is fetched from Coingecko API with a" \
" five minutes interval. \n\nFor bug reports or feature requests " \
"see https://github.com/emre/hivebar. \n\n" \
"Icon set: https://hive.io/brand" % (
VERSION
)
class HiveBarApp(rumps.App):
@rumps.clicked("About")
def about(self, _):
rumps.alert(ABOUT_TEXT)
@rumps.clicked('Change update interval')
def changeit(self, _):
response = rumps.Window('Enter new interval (In seconds)').run()
if response.clicked:
try:
rumps.timer.__dict__["*timers"][0].interval = int(response.text)
rumps.alert("Interval set as %s seconds." % response.text)
except ValueError:
rumps.alert("Invalid value")
@rumps.timer(5)
def update_info(self, _):
r = requests.get(
"https://api.coingecko.com/api/v3/simple/price?ids=hive%2Chive_"
"dollar&vs_currencies=usd&include_24hr_change=true"
).json()
sbd_price_usd = r["hive_dollar"]["usd"]
sbd_price_up = r["hive_dollar"]["usd_24h_change"] > 0
steem_price_usd = r["hive"]["usd"]
steem_price_up = r["hive"]["usd_24h_change"] > 0
self.title = "Hive: $%s %s - HBD: $%s %s " % (
round(float(steem_price_usd), 2),
"🆙" if steem_price_up else "",
round(float(sbd_price_usd), 2),
"🆙" if sbd_price_up else "",
)
if __name__ == "__main__":
steem_status_bar_app = HiveBarApp("...")
steem_status_bar_app.run()