Get the price of a cryptocurrency

This commit is contained in:
JP
2018-02-04 21:53:43 +01:00
parent 8018f6ffc2
commit 14efa61a0f
2 changed files with 44 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import asyncio
import discord
from discord.ext import commands
from urllib import request
import json, requests
class Cryptocoin(object):
"""Voor al uw crypto currency advies."""
def __init__(self, bot):
self.bot = bot
self.voice_states = {}
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
if (time != "now"):
url += "&ts=" + str(time)
response = requests.get(url)
try:
priceData = json.loads(response.content.decode('utf-8'))
return priceData[id]["EUR"]
except:
print("API ERROR. (coin price)")
return -1
@commands.command(pass_context=True)
@asyncio.coroutine
def coinprice(self, ctx, coinId: str):
"""Geeft de huidige prijs van de desbetreffende crypto currency
Bijv: !coinprice BTC
"""
price = self.getCoinPrice(coinId)
yield from ctx.channel.send(coinId + " is nu " + str(price) + " euro waard.")
+2
View File
@@ -4,6 +4,7 @@ import discord
import Porno import Porno
import Shitpost import Shitpost
import General import General
import Cryptocoin
import logging import logging
import importlib import importlib
@@ -17,6 +18,7 @@ bot.add_cog(Shitpost.Shitpost(bot))
#importlib.import_module('Shitpost') #importlib.import_module('Shitpost')
bot.add_cog(Porno.Porno(bot)) bot.add_cog(Porno.Porno(bot))
bot.add_cog(General.General(bot)) bot.add_cog(General.General(bot))
bot.add_cog(Cryptocoin.Cryptocoin(bot))
tokenfile = open("stroopwafel.token","r") tokenfile = open("stroopwafel.token","r")
token = tokenfile.readline() token = tokenfile.readline()