-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathguide_bot1.py
More file actions
43 lines (30 loc) · 1.4 KB
/
guide_bot1.py
File metadata and controls
43 lines (30 loc) · 1.4 KB
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 telebot
import requests
TOKEN = "telebot_token"
bot = telebot.TeleBot(TOKEN)
YANDEX_TOKEN = 'YANDEX_TOKEN'
HOST_YANDEX_DISK = 'https://cloud-api.yandex.net:443'
@bot.message_handler(commands=['create_folder'])
def create_folder_handler(message):
chat_id = message.chat.id
msg = bot.send_message(chat_id, 'Введите название папки')
bot.register_next_step_handler(msg, create_folder)
def create_folder(message):
path = message.text
headers = {'Authorization': 'OAuth %s' % YANDEX_TOKEN}
request_url = HOST_YANDEX_DISK + '/v1/disk/resources?path=%s' % path
response = requests.put(url=request_url, headers=headers)
if response.status_code == 201:
bot.reply_to(message, "Я создал папку %s" % path)
else:
bot.reply_to(message, '\n'.join(["Произошла ошибка. Текст ошибки", response.text]))
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "Привет. Я учебный бот Нетологии")
@bot.message_handler(commands=['help'])
def send_welcome(message):
bot.reply_to(message, "Вы вызвали команду help. Но я ещё ничего не умею")
if __name__ == '__main__':
print('Бот запущен...')
print('Для завершения нажмите Ctrl+Z')
bot.polling()