nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 34851185be9b6de1528951eaa2e80c22698e9127
parent 6496a00752d51e22fe73ab9da71b8fd566b39f52
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Mon, 19 Jun 2017 10:34:03 +0930

add export info to readme, improve export code

- examples for using export in the readme
- use json.dumps instead of manually building the json list with the for
  loop
- use `indent=2` with json.dumps to pretty-print the data

Diffstat:
MREADME.md | 19+++++++++++++++++++
Msimplenote_cli/sncli.py | 13+++++--------
2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md @@ -212,6 +212,25 @@ echo '{"tags":["testing","new"],"content":"New note!"}' | sncli import - Allowed fields are `content`, `tags`, `systemtags`, `modifydate`, `createdate`, and `deleted`. +### Exporting + +sncli can export notes as json data to stdout. Example: + +``` +# export a single note by id +sncli -k somekeyid export + +# export all notes +sncli export + +# export notes matching search string +sncli [-r] export some search keywords or regex +``` + +Note that sncli still stores all the notes data in the directory specified by +`cfg_db_path`, so for easy backups, it may be easier/quicker to simply backup +this entire directory. + ### Tricks diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -1125,7 +1125,7 @@ def cli_note_export(self, key): self.log('ERROR: Key does not exist') return - print(json.dumps(note)) + print(json.dumps(note, indent=2)) def cli_export_notes(self, regex, search_string): @@ -1134,13 +1134,10 @@ def cli_export_notes(self, regex, search_string): search_string, search_mode='regex' if regex else 'gstyle', sort_mode=self.config.get_config('sort_mode')) - print("[") - for i, n in enumerate(note_list): - if i > 0: - print(",") - self.cli_note_export(n.key) - print("]") - + + notes_data = [n.note for n in note_list] + print(json.dumps(notes_data, indent=2)) + def cli_note_edit(self, key): note = self.ndb.get_note(key)