-
Notifications
You must be signed in to change notification settings - Fork 4
/
ltc_price.py
37 lines (32 loc) · 1.06 KB
/
ltc_price.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
import asyncio
import json
import urllib.request
import ssl
import iterm2
async def main(connection):
component = iterm2.StatusBarComponent(
short_description='Litecoin Price',
detailed_description='Displays current price of Litecoin',
exemplar='LTC $121.50',
update_cadence=30,
identifier='schnogz.iterm-crypto-components.ltc-price',
knobs=[],
)
@iterm2.StatusBarRPC
async def litecoin_price_coroutine(knobs):
price_url = 'https://api.blockchair.com/litecoin/stats'
try:
context = ssl._create_unverified_context()
request = urllib.request.Request(
price_url,
headers={},
)
price = format(round(json.loads(
urllib.request.urlopen(request, context=context).read().decode()
)['data']['market_price_usd'], 2), ',')
except:
raise
else:
return f'LTC ${price}'
await component.async_register(connection, litecoin_price_coroutine)
iterm2.run_forever(main)