Created
January 16, 2019 22:45
-
-
Save lucaspg96/dc4379c76026c2280ba91c046cef629c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telegram | |
from telegram.ext import Updater, CommandHandler, \ | |
MessageHandler, Filters | |
import logging | |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
import requests as req | |
def get_crypto_coin(name, coin="usd"): | |
url = "https://api.cryptonator.com/api/ticker/{}-{}".format(name,coin) | |
res = req.get(url) | |
return float(res.json()["ticker"]["price"]) | |
#token do @BotFather | |
my_token = "" | |
def start(bot,update): | |
update.message.reply_text("allons-y!") | |
def help(bot, update): | |
update.message.reply_text("Help! I need somebody HELP!") | |
def error(bot,update,error): | |
print(error) | |
def bitcoin(bot, update): | |
c = get_crypto_coin("btc") | |
update.message.reply_text("Bitcoin current value: $ {0:.2f}".format(c)) | |
def ethereum(bot, update): | |
c = get_crypto_coin("eth") | |
update.message.reply_text("Ethereum current value: $ {0:.2f}".format(c)) | |
updater = Updater(my_token) | |
dp = updater.dispatcher | |
dp.add_handler(CommandHandler("start",start)) | |
dp.add_handler(CommandHandler("help",help)) | |
dp.add_handler(CommandHandler("bitcoin",bitcoin)) | |
dp.add_handler(CommandHandler("ethereum",ethereum)) | |
dp.add_error_handler(error) | |
updater.start_polling() | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment