-
Notifications
You must be signed in to change notification settings - Fork 4
/
coinprice.py
56 lines (46 loc) · 2.2 KB
/
coinprice.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
#coinprice.py by x0rnn, shows current bitcoin/ethereum/litecoin price and info
import minqlx
import requests
class coinprice(minqlx.Plugin):
def __init__(self):
self.add_command(("bitcoin", "btc"), self.cmd_bitcoin, 0)
self.add_command(("ethereum", "eth"), self.cmd_ethereum, 0)
self.add_command(("litecoin", "ltc"), self.cmd_litecoin, 0)
self.c1 = "^1"
self.c2 = "^1"
def cmd_bitcoin(self, player, msg, channel):
self.getCoin("bitcoin")
def cmd_ethereum(self, player, msg, channel):
self.getCoin("ethereum")
def cmd_litecoin(self, player, msg, channel):
self.getCoin("litecoin")
@minqlx.thread
def getCoin(self, coin):
@minqlx.next_frame
def printCoin():
if coin == "bitcoin":
self.msg("^7Bitcoin price: ^3${}^7, 1h change: {}{}pct (${})^7, 24h change: {}{}pct (${})".format(round(price_usd, 2), self.c1, change_1h, round((price_usd / 100) * change_1h, 2), self.c2, change_24h, round((price_usd / 100) * change_24h, 2)))
elif coin == "ethereum":
self.msg("^7Ethereum price: ^3${}^7, 1h change: {}{}pct (${})^7, 24h change: {}{}pct (${})".format(round(price_usd, 2), self.c1, change_1h, round((price_usd / 100) * change_1h, 2), self.c2, change_24h, round((price_usd / 100) * change_24h, 2)))
elif coin == "litecoin":
self.msg("^7Litecoin price: ^3${}^7, 1h change: {}{}pct (${})^7, 24h change: {}{}pct (${})".format(round(price_usd, 2), self.c1, change_1h, round((price_usd / 100) * change_1h, 2), self.c2, change_24h, round((price_usd / 100) * change_24h, 2)))
try:
r = requests.get("https://api.coinmarketcap.com/v1/ticker/" + coin)
try:
r = r.json()
except:
return
except requests.exceptions.RequestException:
return
price_usd = r[0]["price_usd"]
change_1h = r[0]["percent_change_1h"]
change_24h = r[0]["percent_change_24h"]
if change_1h < 0:
self.c1 = "^1"
else:
self.c1 = "^2"
if change_24h < 0:
self.c2 = "^1"
else:
self.c2 = "^2"
printCoin()