-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (59 loc) · 1.99 KB
/
Copy pathapp.py
File metadata and controls
73 lines (59 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from glob import glob
from pathlib import Path
from os.path import expanduser
import click
from src import taskpaper
from src.things3.db import DB, AreaInfo
from src.things3.hierarchy import Area
DEFAULT_DB_PATH = (
"~/Library/Group Containers"
"/JLMPQHK86H.com.culturedcode.ThingsMac"
"/**/Things Database.thingsdatabase/"
"main.sqlite"
)
OUTPUT_DIR = Path(__file__).parent / "output"
class Main:
def __init__(self, db_path: Path, output_dir: Path, include_logbook: bool):
self.db = DB(db_path)
self.output_dir = output_dir
self.ignore_logbook = not include_logbook
def export_all(self):
self.output_dir.mkdir(exist_ok=True)
print("")
for area in self.db.list_areas():
self.export_area(area)
def export_area(self, area: AreaInfo):
output_path = self.output_dir / f"{area.title}.taskpaper"
print(
f"Exporting '{area.title}' to "
f"'{self.output_dir}/{area.title}.taskpaper'"
)
area = self.db.fetch_area(area.uuid, self.ignore_logbook)
area_as_taskpaper = taskpaper.convert_area(area)
with open(output_path, "w") as output_file:
output_file.write(area_as_taskpaper)
@click.command()
@click.option(
"--dbpath",
default=DEFAULT_DB_PATH,
help="Path to the Things 3 database file. "
"Can use globbing (e.g. `~/**/main-*.sqlite`)",
)
@click.option(
"--output",
default=OUTPUT_DIR,
help="Directory where the exported TaskPaper files should be written",
type=click.Path(file_okay=False),
)
@click.option(
"--include-logbook",
default=False,
help="EXPERIMENTAL: Include the Tasks/Projects that are completed or dropped",
is_flag=True
)
def main(dbpath, output, include_logbook):
if not (matching_db_paths := glob(expanduser(dbpath))):
raise ValueError(f"Invalid DB Path: {dbpath}")
Main(Path(matching_db_paths[0]), output, include_logbook).export_all()
if __name__ == "__main__":
main()