Skip to content

Instantly share code, notes, and snippets.

@lorenzodifuccia
Last active August 20, 2022 00:22
Show Gist options
  • Save lorenzodifuccia/a83b204e4c9020e0b38ba30257be6d84 to your computer and use it in GitHub Desktop.
Save lorenzodifuccia/a83b204e4c9020e0b38ba30257be6d84 to your computer and use it in GitHub Desktop.
(Unpaid version of) Asana Assign To Me as Default Assignee
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! πŸ‘‹πŸ‘‹")
@lorenzodifuccia
Copy link
Author

python3 assign_to_me.py's output:

asana_assign_to_me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment