lazeroffmichael / ticktick-py

Unofficial TickTick API
https://lazeroffmichael.github.io/ticktick-py/
MIT License
215 stars 31 forks source link

How to integrate pomo funcitonality? #19

Open NiBa97 opened 2 years ago

NiBa97 commented 2 years ago

Hi! Really appreciate oyur work, i wonder how you planned to integrate the pomo functionality. If you give me some hints, ill be able to code that as im needing it for a use-case.

lazeroffmichael commented 2 years ago

Hello,

Since the pomo timer is not directly supported through TickTick's Official API, the way it would have to be supported is through looking at the API calls that the web app makes when you perform an action like starting or stopping the pomo timer. Once the endpoint is known for doing the API actions and what data is transmitted in the request, we can copy the format to do it. I have usually figured this out using just FireFox's developer tools and looking at the network calls.

It would be similar to how project functionality is implemented right now in the library. If you want to look at a source example, check out ticktick-py/managers/projects.py and look for the method delete_folder

The unique endpoint for the URL is defined in url, the payload information needed is defined in payload and a post request is made since that is the type of request that the webapp would make for deleting a folder.

I will be spending some time implementing some new features soon, and trying to get pomo to work will be one of those things. If you do want to give a crack at implementing it, I am sure many people including myself would appreciate it if you made a PR!

broskees commented 2 years ago

@lazeroffmichael I'm going to give finding the endpoints for this a shot.

As you have some experience with this, I figured I'd reach out to you and see if I'm even in the right ballpark as to how I'm trying to find these.

I was able to get a list of base urls and such being used on the statistics page with the pomo/focus data and their corresponding variable names, but that's about as far as I could get.

Where would you go next?

Variables Domains
domain ticktick.com
api_domain api.ticktick.com \|\| ${domain}
ex_api_domain ext.ticktick.com \|\| ex.${domain}
API_HOST https://${api_domain}/api/v2
API_HOST_V2 ${API_HOST}
API_HOST_V2_PUB https://${api_domain}/pub/api/v2
API_HOST_V1_PUB https://${api_domain}/pub/api/v1
VERSION_API_HOST ${API_HOST}
API_HOST_V3 https://${api_domain}/api/v3
API_HOST_V1 https://${api_domain}/api/v3
MOCK_API_HOST_V2 https://192.168.1.161:7300/mock/${random_string}/api/v2
EX_API_HOST https://${ex_api_domain}/
API_HOST_V4 https://${api_domain}/api/v4
API_SERVERLESS https://pull.${domain} \|\| https://pull.dida365.com
TRACK_HOST https://x.ticktick.com \|\| https://x.dida365.com \|\| https://x.api-dev.365dida.com

Regex I was searching with in the cdn's web.js file:

(VERSION_|MOCK_|EX_)?(API)(_HOST|_SERVERLESS)?(_V[1-9])?(_PUB)?|(ex_)?(api_)?(domain)|(TRACK_HOST)|((ticktick|dida365|365dida).com)
broskees commented 2 years ago

@NiBa97 @lazeroffmichael

Figured some things out, try this out:

client = TickTickClient(email, password, auth_client)

url = client.BASE_URL + 'pomodoros/timeline'

response = client.http_get(
    url,
    cookies=client.cookies,
    header=client.HEADERS
)

print(response)
broskees commented 2 years ago

These are all the requests I could find related to pomodoros/focus

Request Params Headers
POST /pomodoro/task/bind?pomodoroId=${pomodoroId}&projectId=${projectId}&taskId=${taskId} pomodoroId, projectId, taskId -
DELETE /pomodoro/${someVar} ??? -
DELETE /pomodoro/timing/${someVar} ??? -
POST /pomodoro/habit/bind?pomodoroId=${pomodoroId}&habitId=${habitId} pomodoroId, habitId -
POST /pomodoro/timing/habit/bind?timingId=${timingId}&habitId=${habitId} timingId, habitId -
POST /pomodoro/timing/task/bind?timingId=${timingId}&projectId=${projectId}&taskId=${taskId} timingId, projectId, taskId -
POST /batch/pomodoro/timing - unknown
POST /batch/pomodoro - unknown
GET /pomodoros/timeline?to=${someVar} OR /pomodoros/timeline unknown -
GET /pomodoros/statistics/${someVar} unknown -
GET /pomodoros/statistics/${someVar}/${someVar} unknown, unknown -
GET /pomodoros/timing?from=${someVar OR 0}&to=${someVar or empty} unknown, unknown -
GET /pomodoros?from=${someVar OR 0}&to=${someVar or empty} unknown, unknown -
lazeroffmichael commented 2 years ago

Nice! This is actually super helpful. Is there any specific functionalities that you guys believe are most important to have

broskees commented 2 years ago

@lazeroffmichael I posted a PR with a start on this stuff. Unfortunately that's all I have time for for the time being.

I'd love to be able to: