Use of multiple currencies. -1 fix.

This commit is contained in:
JP
2018-02-05 22:58:39 +01:00
parent 14efa61a0f
commit 6ded0fee8e
+21 -9
View File
@@ -13,9 +13,9 @@ class Cryptocoin(object):
def __check(self, ctx): #Todo: Is dit het geld-verdienen kanaal? def __check(self, ctx): #Todo: Is dit het geld-verdienen kanaal?
return True return True
def getCoinPrice(self, id, time="now"): def getCoinPrice(self, coinId, currencyId="USD", time="now"):
url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=EUR&fsym=" + id url = "https://min-api.cryptocompare.com/data/pricehistorical?tsyms=" + currencyId + "&fsym=" + coinId
if (time != "now"): if (time != "now"):
url += "&ts=" + str(time) url += "&ts=" + str(time)
@@ -23,20 +23,32 @@ class Cryptocoin(object):
try: try:
priceData = json.loads(response.content.decode('utf-8')) priceData = json.loads(response.content.decode('utf-8'))
return priceData[id]["EUR"] return priceData[coinId][currencyId]
except: except:
print("API ERROR. (coin price)")
return -1 return -1
@commands.command(pass_context=True) @commands.command(pass_context=True)
@asyncio.coroutine @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 """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.")