Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from todoist_api_python.api import TodoistAPI
- from dotenv import load_dotenv
- import os
- import logging
- # Doc SDK: https://developer.todoist.com/rest/v1/?python#python-sdk
- load_dotenv()
- logging.basicConfig(filename='/var/log/todoist-shopping.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
- logging.info('====================')
- logging.info('Inicio del proceso')
- # Fetch tasks synchronously
- source_project = os.getenv('SOURCE_PROJECT_ID')
- dest_project = os.getenv('DEST_PROJECT_ID')
- query=os.getenv('QUERY')
- api = TodoistAPI(os.getenv('API_TOKEN'))
- keywords=os.getenv('KEYWORD').split(',')
- logging.debug(keywords)
- # Get candidate tasks
- try:
- tasks = api.get_tasks(project_id=source_project,filter=query)
- logging.debug(tasks)
- except Exception as error:
- logging.error(error)
- for task in tasks:
- logging.debug(task)
- for keyword in keywords:
- # If the task has any keyword
- if (task.content.lower().startswith(keyword.lower())):
- logging.info("Task `" + task.content + "` matches with keyword " + keyword)
- # Copy the task to the desired destination, minus the keyword
- # (Todoist API doesn't allow to move a task)
- logging.info("Copying the task")
- try:
- new_task = api.add_task(
- content=task.content.lower().replace(keyword.lower(),''),
- due_lang='es',
- project_id=dest_project
- )
- logging.info(new_task)
- except Exception as error:
- logging.error(error)
- # Before deleting the original task, remove date so it won't show in Google Calendar
- try:
- logging.info("Updating original task")
- is_success_update = api.update_task(task_id=task.id, due_string='no due date')
- logging.info(is_success_update)
- except Exception as error:
- logging.error(error)
- # Delete the original task
- try:
- logging.info("Deleting original task")
- is_success_delete = api.delete_task(task_id=task.id)
- logging.info(is_success_delete)
- except Exception as error:
- logging.error(error)
- logging.info('Final del proceso')
Advertisement
Add Comment
Please, Sign In to add comment