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

Deleting Task Doesn't Update Timestamp #28

Closed
typkrft opened this issue May 16, 2022 · 5 comments
Closed

Deleting Task Doesn't Update Timestamp #28

typkrft opened this issue May 16, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@typkrft
Copy link

typkrft commented 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()
@typkrft
Copy link
Author

typkrft commented May 16, 2022

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

@kolaente
Copy link
Member

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 kolaente added the enhancement New feature or request label May 18, 2022
@typkrft
Copy link
Author

typkrft commented 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!

@kolaente
Copy link
Member

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
Copy link
Member

This is now implemented.

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

No branches or pull requests

2 participants