Diff

from v0.1.0 to v0.1.1

Diffstat

 README.md | 28 ++++++++------
 contrib/sncli_to_nn.py | 86 ++++++++++++++++++++++++++++++++++++++++++++
 nnotes_cli/__init__.py | 2 
 nnotes_cli/notes_db.py | 5 +-
 setup.py | 5 ++

README.md

4 4 NextCloud Notes Command Line Interface
5 5
6 6 nncli is a Python application that gives you access to your NextCloud
7 -Notes account via the command line. It's a fork of
7 +Notes account via the command line. It's a "hard" fork of
8 8 [sncli](https://github.com/insanum/sncli). You can access your notes via
9 9 a customizable console GUI that implements vi-like keybinds or via a
10 10 simple command line interface that you can script.
. . .
105 105 #### Configuration
106 106
107 107 The current NextCloud Notes API does not support oauth authentication so
108 -your NextCloud Notes account information must live in the configuration
109 -file. Please be sure to protect this file.
108 +your NextCloud Notes account password must be stored someplace
109 +accessible to nncli. Use of the `cfg_nn_password_eval` option is
110 +recommended (see below).
110 111
111 112 nncli pulls in configuration from the `config` file located in your
112 -$XDG_CONFIG_HOME/nncli directory. (By default,
113 -XDG_CONFIG_HOME=$HOME/.config.) At the very least, the following example
113 +`$XDG_CONFIG_HOME/nncli` directory. (By default,
114 +`XDG_CONFIG_HOME=$HOME/.config`.) At the very least, the following example
114 115 `config` will get you going (using your account information):
115 116
116 117 ```
. . .
133 134
134 135 ```
135 136 [nncli]
136 -cfg_sn_username = lebowski@thedude.com
137 -cfg_sn_password = nihilist
137 +cfg_nn_username = lebowski@thedude.com
138 +cfg_nn_password = nihilist
139 +cfg_nn_host = nextcloud.thedude.com
138 140
139 -# as an alternate to cfg_sn_password you could use the following config item
141 +# as an alternate to cfg_nn_password you could use the following config item
140 142 # any shell command can be used; its stdout is used for the password
141 143 # trailing newlines are stripped for ease of use
142 -# note: if both password config are given, cfg_sn_password will be used
143 -cfg_sn_password_eval = gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.nncli-pass.gpg
144 +# note: if both password config are given, cfg_nn_password will be used
145 +cfg_nn_password_eval = gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.nncli-pass.gpg
144 146
145 147 # see http://urwid.org/manual/userinput.html for examples of more key
146 148 # combinations
. . .
222 224 ### Creating from command line
223 225
224 226 ```
225 -# create a new note and open in editor nncli create
227 +# create a new note and open in editor
228 +nncli create
226 229
227 -# create a new note with contents of stdin echo 'hi' | nncli create -
230 +# create a new note with contents of stdin
231 +echo 'hi' | nncli create -
228 232 ```
229 233
230 234 ### Importing

contrib/sncli_to_nn.py (created)

1 +#
2 +# The MIT License (MIT)
3 +#
4 +# Copyright (c) 2018 Daniel Moch
5 +#
6 +# Permission is hereby granted, free of charge, to any person obtaining a copy
7 +# of this software and associated documentation files (the "Software"), to deal
8 +# in the Software without restriction, including without limitation the rights
9 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 +# copies of the Software, and to permit persons to whom the Software is
11 +# furnished to do so, subject to the following conditions:
12 +#
13 +# The above copyright notice and this permission notice shall be included in all
14 +# copies or substantial portions of the Software.
15 +#
16 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 +# SOFTWARE.
23 +#
24 +"""
25 +sncli_to_nn.py
26 +
27 +Simplenote to NextCloud Notes
28 +
29 +This script imports a folder of json-formatted sncli notes and uploads
30 +them to the specified NextCloud Notes account.
31 +
32 +NOTE: Tags are ignored in the conversion.
33 +"""
34 +import json
35 +import logging
36 +import os
37 +import requests
38 +import sys
39 +
40 +API_URL = 'https://{}:{}@{}/index.php/apps/notes/api/v0.2/notes'
41 +
42 +def convert(sn):
43 + nn = {}
44 + nn['content'] = sn['content']
45 + nn['modified'] = int(sn['modifydate'].split('.')[0])
46 + nn['favorite'] = 'true' if 'pinned' in sn['systemtags'] else 'false'
47 + if len(sn['tags']) != 0:
48 + print("WARNING: Ignoring tags in note " + sn['key'] + '.json')
49 + return nn
50 +
51 +def upload(nn, url):
52 + res = requests.post(url, data=nn)
53 +
54 +def sncli_to_nn(sndb_path, nn_host, nn_user, nn_pw):
55 + sndb_path = os.path.expanduser(sndb_path)
56 + url = API_URL.format(nn_user, nn_pw, nn_host)
57 + if not os.path.isdir(sndb_path):
58 + usage("Provided sndb_path does not exist or is not a directory")
59 +
60 + for filename in os.listdir(sndb_path):
61 + if filename.endswith('.json'):
62 + with open(os.path.join(sndb_path, filename), 'r') as notefile:
63 + nn = convert(json.load(notefile))
64 +
65 + upload(nn, url)
66 +
67 +def usage(message=None):
68 + if message is not None:
69 + print("ERROR: " + message)
70 +
71 + print("""
72 +Usage:
73 + python3 sncli_to_nn.py sndb_path nn_host nn_user nn_pw
74 +
75 + sndb_path - sncli notes database path
76 + nn_host - NextCloud host
77 + nn_user - NextCloud account username
78 + nn_pw - NextCloud account password
79 +""")
80 + exit(1)
81 +
82 +if __name__ == '__main__':
83 + if len(sys.argv) != 5:
84 + usage("Wrong number of arguments")
85 +
86 + sncli_to_nn(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

nnotes_cli/__init__.py

1 1 __productname__ = 'nncli'
2 -__version__ = '0.1.0'
2 +__version__ = '0.1.1'
3 3 __copyright__ = "Copyright (c) 2018 Daniel Moch"
4 4 __author__ = "Daniel Moch"
5 5 __author_email__ = "daniel@danielmoch.com"

nnotes_cli/notes_db.py

306 306 if not isinstance(new_note['content'], str):
307 307 raise ValueError('"content" must be a string')
308 308
309 - for n in (new_note['modified']):
310 - if not 0 <= n <= timestamp:
311 - raise ValueError('date fields must be real')
309 + if not 0 <= new_note['modified'] <= timestamp:
310 + raise ValueError('"modified" field must be real')
312 311
313 312 if not isinstance(new_note['category'], str) or \
314 313 new_note['category'] is None:

setup.py

31 31
32 32 deps = ['urwid', 'requests']
33 33
34 +with open("README.md", "r") as fh:
35 + long_description = fh.read()
36 +
34 37 setup(
35 38 name=nnotes_cli.__productname__,
36 39 description=nnotes_cli.__description__,
40 + long_description=long_description,
41 + long_description_content_type="text/markdown",
37 42 version=nnotes_cli.__version__,
38 43 author=nnotes_cli.__author__,
39 44 author_email=nnotes_cli.__author_email__,