nncli

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

commit 6496a00752d51e22fe73ab9da71b8fd566b39f52
parent e2897348086603ab498074c1b11736592c1d630a
Author: Gervase Markham <gerv@gerv.net>
Date:   Wed, 31 May 2017 11:01:56 +0100

Add export as JSON

Diffstat:
Msimplenote_cli/sncli.py | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -1118,6 +1118,29 @@ def cli_note_import(self, from_stdin): self.log('(IMPORT) ValueError: {}'.format(e)) sys.exit(1) + def cli_note_export(self, key): + + note = self.ndb.get_note(key) + if not note: + self.log('ERROR: Key does not exist') + return + + print(json.dumps(note)) + + def cli_export_notes(self, regex, search_string): + + note_list, match_regex, all_notes_cnt = \ + self.ndb.filter_notes( + 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("]") + def cli_note_edit(self, key): note = self.ndb.get_note(key) @@ -1197,6 +1220,7 @@ def usage(): dump [search_string] - dump notes (refined with search string) create [-] - create a note ('-' content from stdin) import [-] - import a note in JSON format ('-' JSON from stdin) + export - export a note in JSON format (specified by <key>) dump - dump a note (specified by <key>) edit - edit a note (specified by <key>) < trash | untrash > - trash/untrash a note (specified by <key>) @@ -1287,6 +1311,14 @@ def sncli_start(sync=sync, verbose=verbose, config=config): else: usage() + elif args[0] == 'export': + + sn = sncli_start() + if key: + sn.cli_note_export(key) + else: + sn.cli_export_notes(regex, ' '.join(args[1:])) + elif args[0] == 'edit': if not key: