Skip to content

Commit

Permalink
add export note
Browse files Browse the repository at this point in the history
  • Loading branch information
Nriver committed Mar 27, 2023
1 parent 1a6b2f8 commit fbb5a74
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 25 additions & 0 deletions src/trilium_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fbb5a74

Please sign in to comment.