Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from todoist_api_python.api import TodoistAPI
- import json
- from datetime import date
- import datetime
- CLIENT_ID = '01fd238f1dca45c0b6a2ffdb3ff9d601'
- CLIENT_SECRET = '51376de7dfe946418eff3c149f11cc54'
- TEST_TOKEN = '38847922db0efe60a38e91fe73ec190f19f2ecfb'
- api = TodoistAPI(TEST_TOKEN)
- def get_project_id(project_name):
- projects = api.get_projects()
- myprojects = []
- for project in projects:
- if (project.name == project_name):
- myprojects.append(project.id)
- if len(myprojects) <= 0:
- # Not Found
- return None
- if len(myprojects) > 1:
- # too many objects
- return None
- return myprojects[0]
- def delete_project(name):
- id = get_project_id(name)
- try:
- s = api.delete_project(project_id=id)
- except Exception as error:
- return error
- def add_project(name, parent_name=None, view_style='list', color= "charcoal"):
- try:
- res = get_projects_names()
- if len(res) >= 7:
- return 'Переполнение. Купите тариф Про.'
- parent_id = get_project_id(parent_name)
- project = api.add_project(name=name, parent_id=parent_id, view_style=view_style, color=color)
- return project.id
- except Exception as error:
- return(error)
- def get_projects_names(url=False)->list:
- try:
- projects = api.get_projects()
- if (url):
- projects_names = [[project.name, project.url] for project in projects]
- else:
- projects_names = [project.name for project in projects]
- #print(projects_names)
- return projects_names
- except Exception as error:
- return error
- def rename_project(old_name, new_name):
- try:
- project_id = get_project_id(old_name)
- project = api.update_project(project_id=project_id, name=new_name)
- return project.url
- except Exception as error:
- return error
- def get_tasks(project_name=None):
- project_id = get_project_id(project_name)
- tasks = api.get_tasks(project_id=project_id)
- return tasks
- import telebot
- from telebot import types
- import requests
- import json
- import os
- api_token = '6899437684:AAHuhona7h1r4kPmQTGe-SRULunPkWEqbg0'
- bot = telebot.TeleBot(api_token)
- d = dict()
- # @bot.message_handler()
- # def info(message):
- # if (message.text.lower() == 'id'):
- # bot.reply_to(message, f'Your ID is {message.from_user.id}')
- @bot.message_handler(commands = ["start"])
- def start(message):
- bot.send_message(message.chat.id, f"Hello, {message.from_user.first_name} {message.from_user.last_name}!")
- @bot.message_handler(commands=["help"])
- # @bot.message_handler(content_types=["photo"])
- def help(message):
- markup = types.InlineKeyboardMarkup()
- markup.add(types.InlineKeyboardButton("Посмотреть id проекта", callback_data= 'get_project_id'))
- markup.add(types.InlineKeyboardButton("Удалить проект", callback_data='delete_project'))
- markup.add(types.InlineKeyboardButton("Добавить проект", callback_data='add_project'))
- markup.add(types.InlineKeyboardButton("Изменить имя проекта", callback_data='rename_project'))
- bot.reply_to(message, "Help information", reply_markup = markup)
- @bot.callback_query_handler(func = lambda callback: True)
- def callback_message(callback):
- if callback.data == 'get_project_id':
- mesg = bot.send_message(callback.message.chat.id, 'Введите название проекта')
- bot.register_next_step_handler(mesg, get_proj_id)
- elif callback.data == 'delete_project':
- mesg = bot.send_message(callback.message.chat.id, 'Введите название проекта')
- bot.register_next_step_handler(mesg, del_proj_id)
- elif callback.data == 'add_project':
- mesg = bot.send_message(callback.message.chat.id, 'Введите название проекта')
- bot.register_next_step_handler(mesg, add_proj)
- elif callback.data == 'rename_project':
- mesg = bot.send_message(callback.message.chat.id, 'Введите старое название проекта')
- bot.register_next_step_handler(mesg, rename_proj)
- def get_proj_id(message):
- bot.send_message(message.chat.id, f'id проекта {get_project_id(message.text)}')
- def del_proj_id(message):
- delete_project(message.text)
- bot.send_message(message.chat.id, 'Проект удален')
- def add_proj(message):
- add_project(message.text)
- bot.send_message(message.chat.id, 'Проект добавлен')
- def rename_proj(message):
- d[message.chat.id] = message.text
- mesg = bot.send_message(message.chat.id, 'Введите новое название проекта')
- bot.register_next_step_handler(mesg, add_proj_set_new)
- def add_proj_set_new(message):
- rename_project(d[message.chat.id], message.text)
- bot.send_message(message.chat.id, 'Проект переименован')
- bot.infinity_polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement