Use of multiple currencies. -1 fix.
This commit is contained in:
+20
-8
@@ -13,8 +13,8 @@ class Cryptocoin(object):
|
||||
def __check(self, ctx): #Todo: Is dit het geld-verdienen kanaal?
|
||||
return True
|
||||
|
||||
def getCoinPrice(self, id, time="now"):
|
||||
url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=EUR&fsym=" + id
|
||||
def getCoinPrice(self, coinId, currencyId="USD", time="now"):
|
||||
url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId
|
||||
|
||||
if (time != "now"):
|
||||
url += "&ts=" + str(time)
|
||||
@@ -23,20 +23,32 @@ class Cryptocoin(object):
|
||||
|
||||
try:
|
||||
priceData = json.loads(response.content.decode('utf-8'))
|
||||
return priceData[id]["EUR"]
|
||||
return priceData[coinId][currencyId]
|
||||
except:
|
||||
print("API ERROR. (coin price)")
|
||||
return -1
|
||||
|
||||
@commands.command(pass_context=True)
|
||||
@asyncio.coroutine
|
||||
def coinprice(self, ctx, coinId: str):
|
||||
def coinprice(self, ctx, coinId: str, currencyId: str="USD"):
|
||||
"""Geeft de huidige prijs van de desbetreffende crypto currency
|
||||
Bijv: !coinprice BTC
|
||||
Bijv:
|
||||
!coinprice BTC
|
||||
Of voor de echte (Erik) Hollanders:
|
||||
!coinprice NLG EUR
|
||||
"""
|
||||
price = self.getCoinPrice(coinId)
|
||||
allowedCurrencies = ["USD", "EUR", "JPY", "GBP", "CNY", "CAD", "BTC"]
|
||||
|
||||
yield from ctx.channel.send(coinId + " is nu " + str(price) + " euro waard.")
|
||||
if (currencyId not in allowedCurrencies):
|
||||
yield from ctx.channel.send("Valuta " + currencyId + " ken ik niet. :disappointed: ")
|
||||
return
|
||||
|
||||
price = self.getCoinPrice(coinId, currencyId)
|
||||
|
||||
if (price == -1):
|
||||
yield from ctx.channel.send("Die cryptocoin ken ik niet... :frowning2: ")
|
||||
return
|
||||
|
||||
yield from ctx.channel.send(coinId + " is nu " + str(price) + " " + currencyId + " waard.")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user