-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (53 loc) · 2.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from random import choice
import telebot
token = '5717734841:AAHigJ6JrEpzprJKGcsHSOJOyhPgLiT6dJk'
bot = telebot.TeleBot(token)
RANDOM_TASKS = ['Сходить на прогулку', 'Выучить новый язык программирования', 'Приготовить что-то вкусное',
'Начать смотреть новый сериал'] # спсибо можно расширять
todos = dict()
HELP = """
Список доступных команд:
* print - напечатать все задачи на заданную дату в формате 'Дата' 'Задача'
* add_todo - добавить задачу в формате 'Дата Задача'
* random - добавить на сегодня случайную задачу
* help - Напечатать help
"""
def add_todo(date, task):
date = date.lower()
if todos.get(date) is not None:
todos[date].append(task)
else:
todos[date] = [task]
@bot.message_handler(commands=['help'])
def help(message):
bot.send_message(message.chat.id, HELP)
bot.send_message(message.chat.id, 'Команды должны записываться с "/" знаком перед текстом')
@bot.message_handler(commands=['random'])
def random_task(message):
task = choice(RANDOM_TASKS)
add_todo('сегодня', task)
bot.send_message(message.chat.id, f'Задача "{task}" добавлена на сегодня')
@bot.message_handler(commands=['add_todo'])
def add(message):
_, date, task = message.text.split(maxsplit=2)
if len(task) < 3:
bot.send_message(message.chat.id, 'Задачи должны быть больше 3-х символов')
return
add_todo(date, task)
bot.send_message(message.chat.id, f'Задача "{task}" добавлена на дату {date}')
@bot.message_handler(commands=['print'])
def print_(message):
# TODO: 2
dates = message.text.split(maxsplit=1)[1].lower().split()
response = ''
for date in dates:
tasks = todos.get(date)
if tasks:
response += f'{date}: \n'
for task in tasks:
response += f'[ ] {task}\n'
response += '\n'
else:
response += f'На {date} задач нет\n\n'
bot.send_message(message.chat.id, response)
bot.polling(none_stop=True)