Created
June 15, 2020 05:10
-
-
Save falkben/4e1b41617b7f1037266e23fd8a68cfd7 to your computer and use it in GitHub Desktop.
convert an asana project exported to json into a trello board
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
# To add a new cell, type '# %%' | |
# To add a new markdown cell, type '# %% [markdown]' | |
# %% | |
import json | |
import requests | |
import time | |
# %% | |
projects = [ | |
("backend", "backend"), | |
("blog", "Blog"), | |
("deployment", "deployment"), | |
("feature_requests", "Feature request"), | |
("frontend", "frontend"), | |
("marketing", "marketing"), | |
] | |
colors = [ | |
"yellow", | |
"purple", | |
"blue", | |
"red", | |
"green", | |
"orange", | |
"black", | |
"sky", | |
"pink", | |
"lime", | |
] | |
key_mapping = [ | |
("name", "name"), | |
("notes", "description"), | |
# ("completed", ), | |
# ("completed_at", ), | |
# ("created_at", ), | |
# ("parent", ), | |
# ("projects", ), | |
] | |
with open("/home/ben/repos/zootable/trello/trello_token.json", "r") as f: | |
trello_tokens = json.load(f) | |
trello_key = trello_tokens["key"] | |
trello_token = trello_tokens["token"] | |
url = "https://api.trello.com/1/" | |
headers = {"Accept": "application/json"} | |
token_url = f"?key={trello_key}&token={trello_token}" | |
# %% | |
# get the boards | |
resp = requests.get(f"{url}/members/me/boards{token_url}&fields=name", headers=headers) | |
boards = resp.json() # important info here is `id` | |
board_id = boards[0]["id"] | |
# %% | |
# getting the board list | |
resp = requests.get(f"{url}/boards/{board_id}/lists{token_url}", headers=headers) | |
board_list_data = resp.json() | |
for bl in board_list_data: | |
if bl["name"] == "Things To Do": | |
board_list_id = bl["id"] | |
break | |
# %% | |
# create the labels | |
project_ids = {} | |
for i, project in enumerate(projects): | |
name = project[0] | |
color = colors[i] | |
path = f"{url}labels{token_url}&name={project[0]}&color={color}&idBoard={board_id}" | |
resp = requests.post(path) | |
resp_data = resp.json() | |
project_ids[project[0]] = resp_data["id"] | |
# %% | |
for project in projects: | |
with open(f"/home/ben/repos/zootable/trello/data/{project[0]}.json", "r") as f: | |
data = json.load(f) | |
# create the cards | |
for task in data["data"]: | |
if not task["completed"]: | |
name = task["name"] | |
desc = task["notes"] | |
pjs = [p["name"] for p in task["projects"]] | |
pjs_name = [p[0] for p in projects if p[1] in pjs] | |
label_ids = ",".join([project_ids[p] for p in pjs_name]) | |
path = f"{url}cards{token_url}&idList={board_list_id}&idLabels={label_ids}&name={name}&desc={desc}" | |
resp = requests.post(path) | |
print(resp.status_code) | |
time.sleep(0.5) | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment