From 6ded0fee8e1d9ece8eb960d0a1e6cf49d36331d9 Mon Sep 17 00:00:00 2001 From: JP Date: Mon, 5 Feb 2018 22:58:39 +0100 Subject: [PATCH] Use of multiple currencies. -1 fix. --- Cryptocoin.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Cryptocoin.py b/Cryptocoin.py index 0b40bae..6f725b9 100644 --- a/Cryptocoin.py +++ b/Cryptocoin.py @@ -13,9 +13,9 @@ 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.") \ No newline at end of file