Files
stroopwafel/Cryptocoin.py
T
2018-02-04 21:53:43 +01:00

42 lines
1.0 KiB
Python

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.")