From d2b094f816bddf04d4df741991d019e6aaa2a7ae Mon Sep 17 00:00:00 2001 From: moorsey Date: Sat, 6 Jan 2024 11:14:19 +0000 Subject: [PATCH 1/5] Added chunking code for API limits --- autodoist.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/autodoist.py b/autodoist.py index 957fa9d..da7ada9 100644 --- a/autodoist.py +++ b/autodoist.py @@ -19,6 +19,18 @@ import re import json + +#chunking + +def sync_in_chunks(api): + chunk_size = 99 # Maximum commands per request + while api.queue: + chunk = api.queue[:chunk_size] # Get the next chunk + api.queue = api.queue[chunk_size:] # Remove the processed chunk from the queue + sync(api, chunk) # Sync the current chunk + + logging.info('Synced chunk of %d commands.', chunk_size) + # Connect to SQLite database @@ -491,8 +503,7 @@ def commit_labels_update(api, overview_task_ids, overview_task_labels): # Update tasks in batch with Todoist Sync API - -def sync(api): +def sync(api, chunk): # # This approach does not seem to work correctly. # BASE_URL = "https://api.todoist.com" # SYNC_VERSION = "v9" @@ -510,7 +521,7 @@ def sync(api): } data = 'sync_token=' + api.sync_token + \ - '&commands=' + json.dumps(api.queue) + '&commands=' + json.dumps(chunk) response = requests.post( 'https://api.todoist.com/sync/v9/sync', headers=headers, data=data) @@ -1520,8 +1531,10 @@ def main(): overview_task_labels) # Sync all queued up changes +# if api.queue: +# sync(api) if api.queue: - sync(api) + sync_in_chunks(api) num_changes = len(api.queue)+len(api.overview_updated_ids) From e4ee51b20d65d8c070d05fe9ea179b5c36ba7481 Mon Sep 17 00:00:00 2001 From: moorsey Date: Sat, 6 Jan 2024 11:16:11 +0000 Subject: [PATCH 2/5] Update autodoist.py --- autodoist.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autodoist.py b/autodoist.py index da7ada9..3b78536 100644 --- a/autodoist.py +++ b/autodoist.py @@ -20,7 +20,7 @@ import json -#chunking +#chunking code to meet API limits of 100 calls per request def sync_in_chunks(api): chunk_size = 99 # Maximum commands per request @@ -1531,8 +1531,6 @@ def main(): overview_task_labels) # Sync all queued up changes -# if api.queue: -# sync(api) if api.queue: sync_in_chunks(api) From 7d54a85880a5ba9278460fc919d6618e6ce0940e Mon Sep 17 00:00:00 2001 From: moorsey Date: Sat, 6 Jan 2024 12:03:03 +0000 Subject: [PATCH 3/5] Create docker-image.yml --- .github/workflows/docker-image.yml | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..6a05e6f --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,41 @@ +name: Build and publish Docker image + +on: + push: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-publish-docker-image: + name: Build and publish Docker image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From b6eacfcc2ee393c8964a227e7cbeaf94bf5c1dc0 Mon Sep 17 00:00:00 2001 From: moorsey Date: Sat, 6 Jan 2024 12:31:57 +0000 Subject: [PATCH 4/5] Update README.md Added docker-compose example --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 6947609..ddcfe3b 100644 --- a/README.md +++ b/README.md @@ -193,3 +193,13 @@ To build the docker container, check out the repository and run: To run autodoist inside the docker container: docker run -it autodoist:latest + +Docker-compose example: + + version: "3.7" + services: + autodoist: + image: ghcr.io/Hoffelhas/autodoist:laster + container_name: autodoist + command: -l=next -hf=2 -a=**apikey** + restart: unless-stopped From 8132b133de716f536b75171fb51d57b3fd5c914b Mon Sep 17 00:00:00 2001 From: moorsey Date: Sat, 6 Jan 2024 12:39:34 +0000 Subject: [PATCH 5/5] Delete .github/workflows/docker-image.yml accidentally created duplicate file --- .github/workflows/docker-image.yml | 41 ------------------------------ 1 file changed, 41 deletions(-) delete mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 6a05e6f..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build and publish Docker image - -on: - push: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-publish-docker-image: - name: Build and publish Docker image - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Log in to the Container registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v3 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }}