From fbb5a743fa8476bf40cb9438b7378fd4de3bffd3 Mon Sep 17 00:00:00 2001 From: Nriver <6752679+Nriver@users.noreply.github.com> Date: Mon, 27 Mar 2023 10:28:58 +0800 Subject: [PATCH] add export note --- setup.py | 2 +- src/trilium_py/client.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b16ac76..36f56b8 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ # For a discussion on single-sourcing the version across setup.py and the # project code, see # https://packaging.python.org/guides/single-sourcing-package-version/ - version='0.7.1', # Required + version='0.7.2', # Required # This is a one-line description or tagline of what your project does. This # corresponds to the "Summary" metadata field: diff --git a/src/trilium_py/client.py b/src/trilium_py/client.py index f7b6ac8..3221692 100644 --- a/src/trilium_py/client.py +++ b/src/trilium_py/client.py @@ -341,6 +341,31 @@ def get_calendar_years(self, year: str) -> dict: res = requests.get(url, headers=self.get_header()) return res.json() + def export_note(self, noteId: str, format: str, savePath: str, chunk_size=128): + """ + Export note by id. Please note that protected notes are not allowed to be exported by ETAPI. + + :param noteId: note id + :param format: format should be "html" or "markdown" or "md" for short + :savePath: path for exported file + :chunk_size: download chunk size, default to 128 + :return: + """ + url = f'{self.server_url}/etapi/notes/{noteId}/export' + if format in ['md', 'markdown']: + format = 'markdown' + else: + format = 'html' + params = { + "format": format, + } + r = requests.get(url, params=clean_param(params), headers=self.get_header()) + print(r.status_code) + with open(savePath, 'wb') as fd: + for chunk in r.iter_content(chunk_size=chunk_size): + fd.write(chunk) + return True + def get_today_note_content(self): date = get_today() return self.get_day_note(date)