This commit is contained in:
Марычев Павел Иванович 2021-07-31 17:37:36 +04:00
commit cee9ce5844
3 changed files with 175 additions and 0 deletions

69
lesson5.py Normal file
View File

@ -0,0 +1,69 @@
from random import choice
import telebot
token = '1876215418:AAHoWRyNkIU6CQymRXdOFAzDBcxwO4vNq-A'
bot = telebot.TeleBot(token)
RANDOM_TASKS = ['Написать Гвидо письмо', 'Выучить Python', 'Записаться на курс в Нетологию', 'Посмотреть 4 сезон Рик и Морти']
todos = dict()
HELP = '''
Список доступных команд:
* print - напечать все задачи на заданную дату
* 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.message_handler(commands=['random'])
def random(message):
task = choice(RANDOM_TASKS)
add_todo('сегодня', task)
bot.send_message(message.chat.id, f'Задача {task} добавлена на сегодня')
@bot.message_handler(commands=['add'])
def add(message):
_, date, tail = message.text.split(maxsplit=2)
task = ' '.join([tail])
# TODO: 1
if len(task) < 3:
bot.send_message(message.chat.id, 'Задачи должны быть больше 3х символов')
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()[1].lower().split()
response = ''
for date in dates:
tasks = todos.get(date)
response += f'{date}: \n'
for task in tasks:
response += f'[ ] {task}\n'
response += '\n'
bot.send_message(message.chat.id, response)
bot.polling(none_stop=True)

61
main.py Normal file
View File

@ -0,0 +1,61 @@
import telebot
from random import choice
token = '1876215418:AAHoWRyNkIU6CQymRXdOFAzDBcxwO4vNq-A'
bot = telebot.TeleBot(token)
HELP = '''
* help - напечатать справку по программе.
* add - добавить задачу в список (название задачи запрашиваем у пользователя).
* show - напечатать все добавленные задачи.
'''
RANDOM_TASKS = ['123','321']
todos =dict()
def add_todo(date, task, category):
if todos.get(date) is not None:
todos[date].extend([[task, category]])
else:
todos[date] = [[task, category]]
@bot.message_handler(commands=['help'])
def echo(message):
bot.send_message(message.chat.id, HELP)
@bot.message_handler(commands=['random'])
def random_task(message):
task = choice(RANDOM_TASKS)
add_todo('сегодня', choice(RANDOM_TASKS), 'рандом')
bot.send_message(message.chat.id, f'Добавлена случайна задача {task}')
@bot.message_handler(commands=['show', 'print'])
def show(message):
dates = message.text.split()
for date in dates[1:]:
date = date.lower()
if date in todos:
reply = date.upper() + '\n'
print(todos)
print(todos[date])
for task, category in todos[date]:
reply += f'[] {task}, @{category}\n'
else:
reply = 'Такой даты нет'
bot.send_message(message.chat.id, reply)
@bot.message_handler(commands=['add', 'todo', 'category'])
def add(message):
splitted_command = message.text.split(maxsplit=3)
date = splitted_command[1]
task = splitted_command[2]
category = splitted_command[3]
if len(task) <3:
bot.send_message(message.chat.id, f'Задача: {task}, меньше 3х символов, добавлена не будет!')
else:
add_todo(date, task, category)
bot.send_message(message.chat.id, f'Добавлена задача: {task}, в день: {date}, категория: @{category}')
bot.polling(none_stop=True)

45
toDo.py Normal file
View File

@ -0,0 +1,45 @@
# Запрашивать у пользователя команду.
# В зависимости от введенной команды выполнять действие.
HELP = '''
* help - напечатать справку по программе.
* add - добавить задачу в список (название задачи запрашиваем у пользователя).
* show - напечатать все добавленные задачи.
'''
tasks = []
today = []
tomorrow = []
other = []
# command = input("Введите команду: ")
while True:
command = input("Введите команду: ")
if command == "help":
print(HELP)
elif command == "add":
task = input("Введите задачу: ")
date = input("Введите дату: ")
if date == "Сегодня":
today.append(task)
elif date == "Завтра":
tomorrow.append(task)
else:
other.append(task)
print("Задача добавлена")
elif command == "show":
print('today tasks:')
for task in today:
print(task)
print('tomorrow tasks:')
for task in tomorrow:
print(task)
print('other tasks:')
for task in other:
print(task)
elif command == "exit":
print("Спасибо за использование! До свидания!")
break
else:
print("Неизвестная команда!")
print(HELP)
break