-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
43 lines (30 loc) · 1.45 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import telegram
from telegram.ext import Updater
from telegram.ext import CommandHandler
from tracker import get_prices
telegram_bot_token = '5101284223:AAGuasvtgsxtypb9n4Eu8Kk7soGqQfspshc'
updater = Updater(token=telegram_bot_token, use_context=True)
dispatcher = updater.dispatcher
def portfolio(update, context):
chat_id = update.effective_chat.id
message = ""
crypto_data = get_prices()
for i in crypto_data:
coin = crypto_data[i]["coin"]
price = crypto_data[i]["price"]
change_day = crypto_data[i]["change_day"]
change_hour = crypto_data[i]["change_hour"]
message += f"Coin: {coin}\nPrice: ${price:,.2f}\nHour Change: {change_hour:.3f}%\nDay Change: {change_day:.3f}%\n\n"
context.bot.send_message(chat_id=chat_id, text=message)
def csv(update, context):
chat_id = update.effective_chat.id
message = "sending the csv file"
context.bot.send_document(chat_id, document=open(r'C:\Users\KIIT\Desktop\bitcoin_tracker\BTC-USD.csv', 'rb'))
def forecast(update, context):
chat_id = update.effective_chat.id
message = "sending the forecast chart"
context.bot.send_photo(chat_id, photo=open(r'C:\Users\KIIT\Desktop\bitcoin_tracker\1.png', 'rb'))
dispatcher.add_handler(CommandHandler("forecast", forecast))
dispatcher.add_handler(CommandHandler("csv", csv))
dispatcher.add_handler(CommandHandler("portfolio", portfolio))
updater.start_polling()