Last active
January 15, 2025 09:50
-
-
Save icaoberg/e0ac4897f92286f60dcf87d970295003 to your computer and use it in GitHub Desktop.
Top 10 Asana Tasks
This file contains 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 os | |
import asana | |
from pathlib import Path | |
from tqdm import tqdm | |
import pandas as pd | |
import warnings | |
warnings.filterwarnings("ignore") | |
# This script fetches tasks from Asana and displays the top 10 incomplete tasks with due dates. | |
# Assumes a secrets file containing the Asana personal access token is located at ~/.ASANA_SECRETS. | |
# The personal access token can be generated from: https://developers.asana.com/docs/personal-access-token | |
# Read Asana secrets from file | |
secrets_file = str(Path.home() / '.ASANA_SECRETS') | |
if not os.path.exists(secrets_file): | |
raise FileNotFoundError("Secrets file not found at ~/.ASANA_SECRETS. Please create the file with your PERSONAL_ACCESS_TOKEN.") | |
# Execute the secrets file to load PERSONAL_ACCESS_TOKEN | |
exec(open(secrets_file).read()) | |
# Initialize Asana client | |
client = asana.Client.access_token(PERSONAL_ACCESS_TOKEN) | |
client.options['client_name'] = 'Jupyter Lab' | |
# Get user information and workspaces | |
me = client.users.get_user("me") | |
workspaces = me['workspaces'] | |
if not workspaces: | |
raise ValueError("No workspaces found for the user. Please ensure your Asana account has access to workspaces.") | |
# Fetch tasks assigned to the user in the second workspace (index 1) | |
tasks = client.tasks.find_all(workspace=workspaces[1]['gid'], assignee='[email protected]') | |
# Collect task metadata | |
todo = [] | |
print("Fetching tasks...") | |
for task in tqdm(tasks, desc="Tasks"): | |
try: | |
tid = task['gid'] | |
tmetadata = client.tasks.find_by_id(task=tid) | |
todo.append({ | |
'due_on': tmetadata['due_on'], | |
'completed': tmetadata['completed'], | |
'description': tmetadata['name'] | |
}) | |
except Exception as e: | |
print(f"Error fetching task details for task ID {task['gid']}: {e}") | |
# Convert task list to a DataFrame | |
df = pd.DataFrame(todo) | |
# Filter and display the top 10 incomplete tasks sorted by due date | |
print('\n# Top 10 Asana Tasks') | |
df = df[df['completed'] == False].sort_values('due_on') | |
if df.empty: | |
print("No incomplete tasks found.") | |
else: | |
print(df.head(10)[['due_on', 'description']].to_markdown(index=False, tablefmt="github")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment