-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.py
28 lines (24 loc) · 1.04 KB
/
coin.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
import requests
import sopel
from sopel import module
from sopel import formatting
@module.commands('coin')
def coin(bot, trigger):
coins = trigger.group(2)
if coins:
coin_list = coins.split(",")
result = []
for name in coin_list:
response = requests.get(f"https://api.coingecko.com/api/v3/search?query={name.strip()}")
json_response = response.json()
if len(json_response["coins"]) == 0:
result.append(f"(404 {name.strip()})")
else:
response_price = requests.get(f"https://api.coingecko.com/api/v3/simple/price?ids={json_response['coins'][0]['id']}&vs_currencies=usd")
data_price = response_price.json()
symbol = formatting.bold(json_response['coins'][0]['symbol'])
price = data_price[json_response['coins'][0]['id']]['usd']
result.append(f"{symbol} {price}")
bot.say("$ " + " ".join(result))
else:
bot.say(".coin crypto or .coin crypto,separated,with,commas")