-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC1t1.py
122 lines (99 loc) · 3.36 KB
/
C1t1.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! /usr/bin/python
# -*- coding: utf-8 -*-
from collections import OrderedDict
import json
import urllib2
import webbrowser
import rumps
__appname__ = 'C1t1'
__author__ = 'Lucy Park'
__description__ = 'Retrieves cryptocurrency prices from Coineone.co.kr every one minute and displays them on the MacOSX menubar.'
__repository__ = 'http://github.com/e9t/c1t1'
__version__ = '0.1.2'
__year__ = '2017'
TICK_INTERVAL = 60 # interval to retrieve ticks (seconds)
COINS = OrderedDict([
('bch', {'icon': u'C'}),
('btc', {'icon': u'\u20BF'}),
('etc', {'icon': u'\uA792'}),
('eth', {'icon': u'\u039E'}),
('qtum', {'icon': u'Q'}),
('xrp', {'icon': u'X'}),
])
COINEX_URL = 'https://coinone.co.kr/exchange'
PRICES_API = 'https://api.coinone.co.kr/ticker/?format=json¤cy'
# declare some static menus
refresh = 'Manually refresh data'
coinex = 'Go to Coinone'
about = 'About %s v%s' % (__appname__, __version__)
class App(rumps.App):
def __init__(self):
super(App, self).__init__(__appname__)
self.coin_menus = OrderedDict()
for coin in COINS:
self.coin_menus[coin] = rumps.MenuItem(coin)
self.coin_menus['btc'].state = 1 # turn on bitcoin
self.menu = self.coin_menus.values() + [refresh, coinex, about]
self.update_prices()
self.update_title()
def update_prices(self):
self.prices = json.loads(urllib2.urlopen(PRICES_API).read())
def update_title(self):
# return coin prices if some coins are selected
title = []
for coin in COINS:
if self.coin_menus[coin].state == 1:
i = COINS[coin]['icon']
p = '{:0,.0f}'.format(int(self.prices[coin]['last']))
title.extend([i, p])
# return appname if no coins are selected
if not title:
title = [__appname__]
self.title = ' '.join(title)
@rumps.timer(TICK_INTERVAL)
def update_all(self, sender):
self.update_prices()
self.update_title()
@rumps.clicked('bch')
def toggle_bch(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked('btc')
def toggle_btc(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked('eth')
def toggle_eth(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked('etc')
def toggle_etc(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked('qtum')
def toggle_qtum(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked('xrp')
def toggle_xrp(self, sender):
sender.state = not sender.state
self.update_title()
@rumps.clicked(refresh)
def refresh_data(self, sender):
self.update_prices()
self.update_title()
@rumps.clicked(coinex)
def goto_coinex(self, sender):
webbrowser.open(COINEX_URL)
@rumps.clicked(about)
def show_about(self, sender):
title = about
message = '\n'.join([
__description__,
'',
'Made by %s (%s).' % (__author__, __year__),
__repository__,
])
rumps.alert(title=title, message=message, ok=None, cancel=None)
if __name__ == '__main__':
App().run(_NOTIFICATIONS=False)