Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect the project with the Sync API v9 #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JSMonk
Copy link

@JSMonk JSMonk commented Nov 15, 2023

First of all, thank you a lot for the project. I miss such kind of dashboard integrated into the Todoist app.
Because I want to use it a lot, I resurrect it with the Todoist Sync API v9, and it works. Please feel free to leave comments if something is implemented in the wrong code style (it's my first interaction with a Python project)

@JSMonk JSMonk changed the title Resurect the project with the Sync API v9 Resurrect the project with the Sync API v9 Nov 15, 2023
@JSMonk
Copy link
Author

JSMonk commented Nov 15, 2023

Also, it fixes the #8 issue

@brunorosilva
Copy link
Owner

Hi, @JSMonk

Thanks for taking the time to code it out. I was actually working on this some time ago, but I couldn't get it to work due to the https://api.todoist.com/sync/v9/archive/items (used by get_completed_items) kinda being broken, they've added a restriction to this method so you can only use it when you use project_id or section_id, see image below. I honestly do not know why they did this, but they shouldn't have.

It seems that you code does not solve this, and it seems that only the API developers (https://github.com/Doist/todoist-api-python) can solve it.

Calling without filter (which should be possible)
image

Calling with filter (which is just silly)
image

@brunorosilva
Copy link
Owner

The only workaround I see is calling the rest/v2/projects endpoint to get all projects and then getting the tasks for each project. The problem with this approach is that I've no way to get archived projects, so some users would be impacted by this method.

@JSMonk
Copy link
Author

JSMonk commented Nov 16, 2023

So, it's only for the archive projects, right? In which of the data frames should this information be added?

@brunorosilva
Copy link
Owner

I'm not sure I was as clear as I could be

The problem

Calling the https://api.todoist.com/sync/v9/archive/items?project_id="123456789" gets all of the completed tasks of a project, the project being archived or not, but it needs the project_id, otherwise it returns a 400.

Calling the https://api.todoist.com/rest/v2/projects gets all of the non-archived projects, and there's no route that I can call to get archived projects.

So, the workaround would be to call the https://api.todoist.com/rest/v2/projects to get all of the project_ids and then iterate over each one calling https://api.todoist.com/sync/v9/archive/items?project_id="123456789".

There's no way to get completed items for archived projects because there's no way to find out the project ids for archived projects.

What code would change

Mainly change the data_collector file to first get all projects using self.api.get_projects() and then in the function _collect_all_completed_tasks do something like

stop_collecting = False
old_shape = 0

for project_id in self.projects["project_id"].unique():
    while not stop_collecting:
        self._collect_completed_tasks(limit=200, offset=self.current_offset, project_id=project_id)
        new_shape = self.items.shape[0]
        if new_shape != old_shape and new_shape < limit:
            old_shape = new_shape
            self.current_offset += 200
        else:
            self.current_offset = new_shape
            stop_collecting = True

@brunorosilva
Copy link
Owner

Hi @JSMonk , they've responded that I could call the sync api. I'll work on the code to do it, given that they've discontinued the sdk for the sync api, so we do not have to make workarounds anymore.

Thanks so much for you input and once I get it back online I'll hit you up and, if you want, create a PR for the README so you can appear as a contributor.

@brunorosilva
Copy link
Owner

@JSMonk just thought I give you an update on how the fix is going. You can check the working branch here. I got everything working on my machine and my plan is to deploy a version using GCP or AWS in this weekend.

@JSMonk
Copy link
Author

JSMonk commented Nov 24, 2023

So, do you think I should close the PR if you don't use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants