Created
June 16, 2020 04:34
-
-
Save falkben/f5bf33dfd7512197a04ede175ec3593c to your computer and use it in GitHub Desktop.
convert an asana project exported to json into a todoist task list
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 json | |
import todoist | |
# %% | |
projects = [ | |
("backend", "backend"), | |
("blog", "Blog"), | |
("deployment", "deployment"), | |
("feature_requests", "Feature request"), | |
("frontend", "frontend"), | |
("marketing", "marketing"), | |
] | |
key_mapping = [ | |
("name", "name"), | |
("notes", "description"), | |
# ("completed", "checked"), | |
# ("completed_at", "date_completed"), | |
# ("created_at", "date_added"), | |
# ("parent", ), | |
# ("projects", ), | |
] | |
with open("/home/ben/repos/asana_export/todoist/todoist_token.json", "r") as f: | |
tokens = json.load(f) | |
token = tokens["api_token"] | |
# %% | |
api = todoist.TodoistAPI(token) | |
api.sync() | |
# %% | |
for project in projects: | |
project_todoist = api.projects.add(project[0]) | |
with open(f"/home/ben/repos/asana_export/asana_data/{project[0]}.json", "r") as f: | |
data = json.load(f) | |
# create the tasks | |
for task in data["data"]: | |
name = task["name"] | |
desc = task["notes"] | |
content = name | |
if desc != "": | |
content += ": " + desc | |
date_added = task["created_at"] | |
date_completed = task["completed_at"] | |
checked = task["completed"] | |
todoist_task = api.items.add( | |
content, | |
project_id=project_todoist["id"], | |
date_added=date_added, | |
date_completed=date_completed, | |
checked=checked, | |
) | |
if checked: | |
todoist_task.complete(date_completed=date_completed) | |
api.commit() | |
# %% | |
# clear out all projects | |
# all_projs = api.state["projects"] | |
# for proj in all_projs: | |
# p = api.projects.get_by_id(proj["id"]) | |
# p.delete() | |
# api.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment