Last active
August 20, 2022 00:22
-
-
Save lorenzodifuccia/a83b204e4c9020e0b38ba30257be6d84 to your computer and use it in GitHub Desktop.
(Unpaid version of) Asana Assign To Me as Default Assignee
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asana | |
class AsanaScript: | |
def __init__(self, secret): | |
self.client = asana.Client.access_token(secret) | |
self.me = self.client.users.me() | |
# Prepare props | |
self.workspaces = [] | |
self.projects = [] | |
self.tasks = [] | |
# Search and assign to me | |
self.get_tasks() | |
self.assign_to_me() | |
def get_tasks(self): | |
self.workspaces = list(self.client.workspaces.get_workspaces()) | |
for w in self.workspaces: | |
self.projects.extend(list(self.client.projects.get_projects({"archived": False, "workspace": w["gid"]}))) | |
for p in self.projects: | |
self.tasks.extend(list(self.client.tasks.get_tasks_for_project(p["gid"], opt_fields=["assignee", ["name"]]))) | |
def assign_to_me(self): | |
new_tasks = list(filter(lambda t: not t["assignee"] or t["assignee"]["gid"] != self.me["gid"], self.tasks)) | |
for t in new_tasks: | |
print(f"β New Task: {t['name']} π Assign to me") | |
self.client.tasks.update_task(t["gid"], {"assignee": self.me["gid"]}) | |
if __name__ == '__main__': | |
script = AsanaScript("{ACCESS TOKEN from https://app.asana.com/0/developer-console}") | |
print("Bye! ππ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 assign_to_me.py
's output: