forked from ivanovs588/telegram_bot_yobit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (36 loc) · 1.42 KB
/
main.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
44
45
import requests
from datetime import datetime
import telebot
from auth_data import token
def get_data():
req = requests.get("https://yobit.net/api/3/ticker/btc_usd")
response = req.json()
sell_price = response["btc_usd"]["sell"]
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M')}\nSell BTC price: {sell_price}")
def telegram_bot(token):
bot = telebot.TeleBot(token)
@bot.message_handler(commands=["start"])
def start_message(message):
bot.send_message(message.chat.id, "Привет! Напишите 'price' чтобы узнать цену BTC!")
@bot.message_handler(content_types=["text"])
def send_text(message):
if message.text.lower() == "price":
try:
req = requests.get("https://yobit.net/api/3/ticker/btc_usd")
response = req.json()
sell_price = response["btc_usd"]["sell"]
bot.send_message(
message.chat.id,
f"{datetime.now().strftime('%Y-%m-%d %H:%M')}\nSell BTC price: {sell_price}"
)
except Exception as ex:
print(ex)
bot.send_message(
message.chat.id,
"Что-то не так)"
)
else:
bot.send_message(message.chat.id, "надо написать 'price'! )
bot.polling()
if __name__ == '__main__':
telegram_bot(token)