From cee9ce58441b11c8538a4e6bb7e8d1196208f18a Mon Sep 17 00:00:00 2001 From: Pavel Marychev Date: Sat, 31 Jul 2021 17:37:36 +0400 Subject: [PATCH] init --- lesson5.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++ toDo.py | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 lesson5.py create mode 100644 main.py create mode 100644 toDo.py diff --git a/lesson5.py b/lesson5.py new file mode 100644 index 0000000..0cfedd9 --- /dev/null +++ b/lesson5.py @@ -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) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..839431a --- /dev/null +++ b/main.py @@ -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) diff --git a/toDo.py b/toDo.py new file mode 100644 index 0000000..1c8b71c --- /dev/null +++ b/toDo.py @@ -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