Deleting Task Doesn't Update Timestamp #49

Closed
opened 2025-11-01 20:45:28 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @Ducky6944 on GitHub (May 16, 2022).

I may be wrong, but it seems that deleting a task doesn't update the tasklist updated timestamp. Creating a new task does.

I'm writing a script that uses the api to send notifications when a list has been updated. Maybe I'm missing something. I'm not a developer and this may be r/badcode lol.

example code:

import requests
from time import sleep
import json


def get_token(url, username, password):
    credentials = {"username": f"{username}", "password": f"{password}"}
    token = requests.post(f"{url}/api/v1/login", json=credentials).json()["token"]
    return (url, token)


def get_tasks(auth):
    db = {}

    tasklists = requests.get(
        f"{auth[0]}/api/v1/lists", headers={"Authorization": f"Bearer {auth[1]}"}
    ).json()
    tasks = requests.get(
        f"{auth[0]}/api/v1/tasks/all", headers={"Authorization": f"Bearer {auth[1]}"}
    ).json()

    for tasklist in tasklists:
        db[tasklist["id"]] = dict(
            name=tasklist["title"], updated=tasklist["updated"], tasks={}, num_tasks=0
        )

    for task in tasks:
        db[task["list_id"]]["tasks"][task["id"]] = dict(
            name=task["title"],
            created=task["created"],
            done=task["done"],
            done_ts=task["done_at"],
            created_by=task["created_by"]["name"],
            updated=task["updated"],
            labels=task["labels"],
            priority=task["priority"],
            notes=task["description"],
        )

    for tasklist in tasklists:
        db[tasklist["id"]]["num_tasks"] = len(db[tasklist["id"]]["tasks"])

    return db


def main():
        auth = get_token("https://vikunja.tld", "user", "password")
    current_db = get_tasks(auth)

    while True:
        sleep(30)
        auth = get_token("https://vikunja.tld", "user", "password")
        new_db = get_tasks(auth)

        for tasklist in current_db.keys():

            # Get Deleted Tasks
            # FIXME: Should be able to check if tasklist has been updated first to avoid unnecesary runs
            deleted_tasks = [
                ("current_db", tasklist, task)
                for task in current_db[tasklist]["tasks"]
                if task not in new_db[tasklist]["tasks"]
            ]
            if len(deleted_tasks) > 0:
                print(deleted_tasks)

            # Check if tasklist has been updated
            if current_db[tasklist]["updated"] == new_db[tasklist]["updated"]:
                continue

            # Get new Tasks
            new_tasks = [
                ("new_db", tasklist, task)
                for task in new_db[tasklist]["tasks"]
                if task not in current_db[tasklist]["tasks"]
            ]
            print("New Tasks:", set_tasks)

            # Get tasks that in both dicts
            set_tasks = [
                ("new_db", tasklist, task)
                for task in new_db[tasklist]["tasks"] and current_db[tasklist]["tasks"]
                if task not in [tup[2] for tup in new_tasks]
                or task not in [tup[2] for tup in deleted_tasks]
            ]
            print("Task Set:", set_tasks)

            # Look for Task Changes
            for task in new_db[tasklist]["tasks"]:
                pass

        current_db = new_db


main()

Originally created by @Ducky6944 on GitHub (May 16, 2022). I may be wrong, but it seems that deleting a task doesn't update the tasklist `updated` timestamp. Creating a new task does. I'm writing a script that uses the api to send notifications when a list has been `updated`. Maybe I'm missing something. I'm not a developer and this may be r/badcode lol. example code: ```PYTHON import requests from time import sleep import json def get_token(url, username, password): credentials = {"username": f"{username}", "password": f"{password}"} token = requests.post(f"{url}/api/v1/login", json=credentials).json()["token"] return (url, token) def get_tasks(auth): db = {} tasklists = requests.get( f"{auth[0]}/api/v1/lists", headers={"Authorization": f"Bearer {auth[1]}"} ).json() tasks = requests.get( f"{auth[0]}/api/v1/tasks/all", headers={"Authorization": f"Bearer {auth[1]}"} ).json() for tasklist in tasklists: db[tasklist["id"]] = dict( name=tasklist["title"], updated=tasklist["updated"], tasks={}, num_tasks=0 ) for task in tasks: db[task["list_id"]]["tasks"][task["id"]] = dict( name=task["title"], created=task["created"], done=task["done"], done_ts=task["done_at"], created_by=task["created_by"]["name"], updated=task["updated"], labels=task["labels"], priority=task["priority"], notes=task["description"], ) for tasklist in tasklists: db[tasklist["id"]]["num_tasks"] = len(db[tasklist["id"]]["tasks"]) return db def main(): auth = get_token("https://vikunja.tld", "user", "password") current_db = get_tasks(auth) while True: sleep(30) auth = get_token("https://vikunja.tld", "user", "password") new_db = get_tasks(auth) for tasklist in current_db.keys(): # Get Deleted Tasks # FIXME: Should be able to check if tasklist has been updated first to avoid unnecesary runs deleted_tasks = [ ("current_db", tasklist, task) for task in current_db[tasklist]["tasks"] if task not in new_db[tasklist]["tasks"] ] if len(deleted_tasks) > 0: print(deleted_tasks) # Check if tasklist has been updated if current_db[tasklist]["updated"] == new_db[tasklist]["updated"]: continue # Get new Tasks new_tasks = [ ("new_db", tasklist, task) for task in new_db[tasklist]["tasks"] if task not in current_db[tasklist]["tasks"] ] print("New Tasks:", set_tasks) # Get tasks that in both dicts set_tasks = [ ("new_db", tasklist, task) for task in new_db[tasklist]["tasks"] and current_db[tasklist]["tasks"] if task not in [tup[2] for tup in new_tasks] or task not in [tup[2] for tup in deleted_tasks] ] print("Task Set:", set_tasks) # Look for Task Changes for task in new_db[tasklist]["tasks"]: pass current_db = new_db main() ```
GiteaMirror added the enhancement label 2025-11-01 20:45:28 -05:00
Author
Owner

@Ducky6944 commented on GitHub (May 16, 2022):

Adding or Removing labels also doesn't seem to change the task['updated'] value like Priority and Descriptions changes do.

@Ducky6944 commented on GitHub (May 16, 2022): Adding or Removing labels also doesn't seem to change the task['updated'] value like Priority and Descriptions changes do.
Author
Owner

@kolaente commented on GitHub (May 18, 2022):

That's correct. Mostly because they are not updated automatically and I didn't explicitly built it so they all update. I think this is somewhere between bug and feature, but definitely undefined behaviour.

If you're up to it, I'd appreciate a PR! Might take some time until I get around to fix it.

@kolaente commented on GitHub (May 18, 2022): That's correct. Mostly because they are not updated automatically and I didn't explicitly built it so they all update. I think this is somewhere between bug and feature, but definitely undefined behaviour. If you're up to it, I'd appreciate a PR! Might take some time until I get around to fix it.
Author
Owner

@Ducky6944 commented on GitHub (May 18, 2022):

Hey thanks for the response. I will certainly look into it and see if it's something I am comfortable tackling, when I get a free minute. I'm not a dev and I don't want to spaghetti code your project and just create more work for you, combing through a terrible pull request lol. But if I can I absolutely will try. Thanks!

@Ducky6944 commented on GitHub (May 18, 2022): Hey thanks for the response. I will certainly look into it and see if it's something I am comfortable tackling, when I get a free minute. I'm not a dev and I don't want to spaghetti code your project and just create more work for you, combing through a terrible pull request lol. But if I can I absolutely will try. Thanks!
Author
Owner

@kolaente commented on GitHub (May 18, 2022):

Sounds great! At least you know more python than I do so I wouldn't say you're not a Dev :)

What you're looking for is this line: https://github.com/go-vikunja/api/blob/main/pkg/models/task_assignees.go#L149

That needs to be added in the relevant places of similar methods.

@kolaente commented on GitHub (May 18, 2022): Sounds great! At least you know more python than I do so I wouldn't say you're not a Dev :) What you're looking for is this line: https://github.com/go-vikunja/api/blob/main/pkg/models/task_assignees.go#L149 That needs to be added in the relevant places of similar methods.
Author
Owner

@kolaente commented on GitHub (Mar 14, 2023):

This is now implemented.

@kolaente commented on GitHub (Mar 14, 2023): This is now implemented.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#49