forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardano.10s.py
executable file
·123 lines (96 loc) · 2.87 KB
/
cardano.10s.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
123
#!/usr/bin/env /usr/local/bin/python3
# coding=utf-8
"""
# <xbar.title>Cardano (ADA) Price Monitor</xbar.title>
# <xbar.version>v0.1</xbar.version>
# <xbar.author>Erol Soyöz</xbar.author>
# <xbar.author.github>soyoz</xbar.author.github>
# <xbar.desc>You can monitor Cardano (ADA)'s latest price via CoinRanking.com API</xbar.desc>
# <xbar.image>https://s15.postimg.cc/4yheazrln/ada.png</xbar.image>
# <xbar.dependencies>python3</xbar.dependencies>
# <xbar.abouturl>http://soyoz.com/</xbar.abouturl>
"""
import json
import textwrap
from urllib.request import urlopen
""
""
COLORS = {
'red': '#b50000',
'green': '#03a600'
}
"""
"""
class BitBarAPI:
@staticmethod
def seperate():
seperate = '---'
return seperate
@staticmethod
def color(hex):
color = 'color=' + hex
return color
@staticmethod
def font(font):
font = 'font=' + font
return font
@staticmethod
def refresh(status):
refresh = 'refresh=' + status
return refresh
"""
"""
class CoinRankingAPI:
@staticmethod
def getCoin(base, coinId):
try:
connect = urlopen(
'https://api.coinranking.com/v1/public/coin/' + coinId + '?base=' + base).read()
except:
return False
return connect
"""
"""
class Cardano:
@staticmethod
def main():
currency = 'USD'
coinId = '9'
getCoin = CoinRankingAPI.getCoin(currency, coinId)
if (getCoin):
result = json.loads(getCoin)
baseSign = result['data']['base']['sign']
symbol = result['data']['coin']['symbol']
price = float(result['data']['coin']['price'])
description = result['data']['coin']['description']
percentChange24h = result['data']['coin']['change']
if (percentChange24h >= 0):
color = COLORS['green']
else:
color = COLORS['red']
outputPrice = '{} ' + baseSign + '{:.3f} | ' + \
BitBarAPI.font('HelveticaNeue-Light') + \
' ' + BitBarAPI.color(color)
outputPrice = outputPrice.format(
symbol,
price
)
print(outputPrice)
print(BitBarAPI.seperate())
outputPercentChange = '24H CHANGE: {}%'
outputPercentChange = outputPercentChange.format(
percentChange24h,
)
print(outputPercentChange)
print(BitBarAPI.seperate())
print(textwrap.fill(description, 30))
else:
print('ERROR! | ' + BitBarAPI.color(COLORS['red']))
print(BitBarAPI.seperate())
print('Failed to connect! | ' + BitBarAPI.color(COLORS['red']))
print(BitBarAPI.seperate())
print('Refresh | ' + BitBarAPI.refresh('true'))
"""
Run!
"""
Cardano.main()