-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (34 loc) · 1.35 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
import requests
import urllib3
from datetime import datetime
import telebot
from token_2 import tele_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(tele_token):
bot = telebot.TeleBot(tele_token)
@bot.message_handler(commands=["start"])
def start_message(message):
bot.send_message(message.chat.id, "Hello ! Type 'price' to get the cost of 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, 'Something went wrong...')
else:
bot.send_message(message.chat.id, 'Incorrect command')
bot.polling()
if __name__ == '__main__':
# get_data()
telegram_bot(tele_token)