├── .github
└── FUNDING.yml
├── requirements.txt
├── export.gif
├── LICENSE
├── README.md
├── .gitignore
└── roam_asana.py
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: Stvad
2 | patreon: stvad
3 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | PyFunctional
2 | dataclasses-json
3 |
--------------------------------------------------------------------------------
/export.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Stvad/RoamAsana/master/export.gif
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Vladyslav Sitalo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ---
3 |
4 | Convert an Asana project to RoamResearch page
5 |
6 | The development is supported by
- a service that allows you to publish your Roam notes as a beautiful static website (digital garden)
7 |
8 | ## Prerequisites:
9 | 1. Python 3.7+
10 | 2. Dependencies:`pip install -r requirements.txt`
11 |
12 | ## Usage
13 | 1. Obtain a JSON representation of your Asana project and save it to `.json`
14 |
15 | 
16 |
17 | You can also use [the exporter](https://github.com/Stvad/AsanaExport) I wrote to obtain a full snapshot of all your projects from all the workspaces.
18 |
19 | 2. Run `python roam_asana.py ProjectName.json output.json`
20 |
21 | 3. Import the resulting JSON file to Roam
22 |
23 | ## Details
24 |
25 | 1. Task notes are inserted as a child block
26 | 1. Subtask become child blocks
27 | 1. Tags and due dates are converted into Roam pages and inserted as a first child block under the respective task block
28 | 1. Sections are supported and tasks that are in a section are aggregated under the same block
29 | 1. This also supports converting [Asana bracket estimate hack](https://github.com/Stvad/RoamAsana) into Roam attribute
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/roam_asana.py:
--------------------------------------------------------------------------------
1 | from __future__ import annotations
2 |
3 | import json
4 | import re
5 | from dataclasses import dataclass, field
6 | from datetime import datetime
7 | from pathlib import Path
8 | from sys import argv
9 | from typing import *
10 |
11 | from dataclasses_json import dataclass_json
12 | from functional import seq
13 |
14 |
15 | # Roam Schema is here: https://roamresearch.com/#/v8/help/page/RxZF78p60
16 | # For Asana, I just looked at the export result
17 |
18 | @dataclass
19 | class Block:
20 | string: str
21 | children: List[Block] = field(default_factory=list)
22 |
23 |
24 | @dataclass_json
25 | @dataclass
26 | class Page:
27 | title: str
28 | children: List[Block]
29 |
30 |
31 | @dataclass
32 | class Task:
33 | task_json: dict
34 |
35 | def as_block(self) -> Block:
36 | return Block(self.roam_name(), self.children())
37 |
38 | def name(self):
39 | return self.task_json['name']
40 |
41 | def roam_name(self):
42 | return "{{[[DONE]]}} " + self.name() if self.task_json['completed'] else self.name()
43 |
44 | def section(self, separator='|'):
45 | """If tasks is in multiple Asana sections - combine them into an aggregate section connected by separator"""
46 | return seq(self.task_json['memberships']).map(lambda it: it['section']['name']).make_string(separator)
47 |
48 | def children(self):
49 | def description():
50 | notes = self.task_json['notes']
51 | return [Block(notes)] if notes else []
52 |
53 | def bracket_estimate(estimate_property="asana_pomodoro_estimate"):
54 | bracket_number = get_bracket_number(self.name())
55 | return [Block(f"{estimate_property}::{bracket_number}")] if bracket_number else []
56 |
57 | def due_date_tag():
58 | return [custom_strftime('%B {S}, %Y', datetime.fromisoformat(self.task_json['due_on']))] \
59 | if self.task_json['due_on'] else []
60 |
61 | def tags():
62 | tag_names = seq(due_date_tag()) + seq(self.task_json['tags']).map(lambda it: it['name'])
63 | tag_str = tag_names.map(lambda it: f"[[{it}]]").make_string(' ')
64 | return [Block(tag_str)] if tag_str else []
65 |
66 | return tags() + bracket_estimate() + description() + convert_tasks(self.task_json['subtasks'])
67 |
68 |
69 | def get_bracket_number(string):
70 | # support for bracket estimates: https://github.com/Stvad/Asana-counter
71 | regex = '\[([-+]?(\d+|\d+\.\d+))]'
72 | match = re.search(regex, string)
73 | if match:
74 | return match.group(1)
75 | return None
76 |
77 |
78 | def custom_strftime(date_format, date):
79 | def suffix(day):
80 | return 'th' if 11 <= day <= 13 else {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th')
81 |
82 | return date.strftime(date_format).replace('{S}', str(date.day) + suffix(date.day))
83 |
84 |
85 | def convert_tasks(tasks):
86 | return (seq(tasks).map(process_task).group_by_key()
87 | .flat_map(extract_sections).to_list())
88 |
89 |
90 | def process_task(task_json):
91 | task = Task(task_json)
92 | return task.section(), task.as_block()
93 |
94 |
95 | def extract_sections(block_pair):
96 | section_name, blocks = block_pair
97 | if (not section_name) or section_name == "(no section)":
98 | return blocks
99 | return [Block(section_name, blocks)]
100 |
101 |
102 | def main():
103 | """Usage roam_asana asana_export.json roam.json"""
104 | input_path = Path(argv[1])
105 | asana = json.load(input_path.open())
106 |
107 | root_page = Page(input_path.stem, convert_tasks(asana['data']))
108 | json_str = root_page.to_json(indent=2)
109 | print(json_str)
110 |
111 | Path(argv[2]).write_text(f"[{json_str}]")
112 |
113 |
114 | if __name__ == '__main__':
115 | main()
116 |
--------------------------------------------------------------------------------