Code Monkey home page Code Monkey logo

sncli's Introduction

sncli

Simplenote Command Line Interface Documentation Status

sncli is a Python application that gives you access to your Simplenote account via the command line. You can access your notes via a customizable console GUI that implements vi-like keybinds or via a simple command line interface that you can script.

Notes can be viewed/created/edited in both an online and offline mode. All changes are saved to a local cache on disk and automatically sync'ed when sncli is brought online.

Pull requests are welcome!

Check your OS distribution for installation packages.

Requirements

Installation

  • Via pip (latest release):
    • pip3 install sncli
  • Manually:
    • Clone this repository to your hard disk: git clone https://github.com/insanum/sncli.git
    • Pipenv:
      • Install the requirements pipenv install
      • Run with pipenv run sncli
    • or more manual:
      • python setup.py install
    • or with Docker (see the wiki for Docker usage tips)
      • docker build . -t sncli
      • docker run --rm -it -v /tmp:/tmp -v "$HOME/.sncli/:/root/.sncli/" -v "$HOME/.snclirc:/root/.snclirc" sncli

Features

  • Console GUI
    • full two-way sync with Simplenote performed dynamically in the background
    • all actions logged and easily reviewed
    • list note titles (configurable format w/ title, date, flags, tags, keys, etc)
    • sort notes by date, alpha by title, tags, pinned on top
    • search for notes using a Google style search pattern or Regular Expression
    • view note contents and meta data
    • view and restore previous versions of notes
    • pipe note contents to external command
    • create and edit notes (using your editor)
    • edit note tags
    • trash/untrash notes
    • pin/unpin notes
    • flag notes as markdown or not
    • vi-like keybinds (fully configurable)
    • Colors! (fully configurable)
  • Command Line (scripting)
    • force a full two-way sync with Simplenote
    • all actions logged and easily reviewed
    • list note titles and keys
    • search for notes using a Google style search pattern or Regular Expression
    • dump note contents
    • create a new note (via stdin or editor)
    • import a note with raw json data (stdin or editor)
    • edit a note (via editor)
    • trash/untrash a note
    • pin/unpin a note
    • flag note as markdown or not
    • view and edit note tags

Screenshots

sncli sncli sncli sncli

HowTo

Usage:
 sncli [OPTIONS] [COMMAND] [COMMAND_ARGS]

 OPTIONS:
  -h, --help                  - usage help
  -v, --verbose               - verbose output
  -n, --nosync                - don't perform a server sync
  -r, --regex                 - search string is a regular expression
  -k <key>, --key=<key>       - note key
  -t <title>, --title=<title> - title of note for create (cli mode)
  -c <file>, --config=<file>  - config file to read from (defaults to ~/.snclirc)

 COMMANDS:
  <none>                      - console gui mode when no command specified
  sync                        - perform a full sync with the server
  list [search_string]        - list notes (refined with search string)
  export [search_string]      - export notes in JSON (refined with search string)
  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 [+line_number]         - edit a note (specified by <key>, optionally jump to line)
  < trash | untrash >         - trash/untrash a note (specified by <key>)
  < pin | unpin >             - pin/unpin a note (specified by <key>)
  < markdown | unmarkdown >   - markdown/unmarkdown a note (specified by <key>)
  tag get                     - retrieve the tags from a note (specified by <key>)
  tag set <tags>              - set the tags for a note (specified by <key>)
  tag add <tags>              - add tags to a note (specified by <key>)
  tag rm <tags>               - remove tags from a note (specified by <key>)

Configuration

The current Simplenote API does not support oauth authentication so your Simplenote account information must live in the configuration file or in the SN_USERNAME and SN_PASSWORD environment variables. Please be sure to protect any file containing these secrets.

The flow sncli uses for finding the config file is:

  1. Specified on the command line with -c or --config.
  2. If SNCLIRC environment variable is set, use that.
  3. Finally will pull from default location of $HOME/.snclirc.

The following example .snclirc will get you going (using your account information):

[sncli]
cfg_sn_username = [email protected]
cfg_sn_password = nihilist

Or, if using environment variables, run sncli like this:

[email protected] SN_PASSWORD=nihilist ./sncli

Start sncli with no arguments which starts the console GUI mode. sncli with start sync'ing all your existing notes and you'll see log messages at the bottom of the console. You can view these log messages at any time by pressing the l key.

View the help by pressing h. Here you'll see all the keybinds and configuration items. The middle column shows the config name that can be used in your .snclirc to override the default setting.

See example configuration file below for more notes.

[sncli]
cfg_sn_username = [email protected]
cfg_sn_password = nihilist

# as an alternate to cfg_sn_password you could use the following config item
# any shell command can be used; its stdout is used for the password
# trailing newlines are stripped for ease of use
# note: if both password config are given, cfg_sn_password will be used
cfg_sn_password_eval = gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sncli-pass.gpg

# see http://urwid.org/manual/userinput.html for examples of more key combinations
kb_edit_note = space
kb_page_down = ctrl f

# note that values must not be quoted
clr_note_focus_bg = light blue

# if this editor config value is not provided, the $EDITOR env var will be used instead
# warning: if neither $EDITOR or cfg_editor is set, it will be impossible to edit notes
cfg_editor = nvim

# alternatively, {fname} and/or {line} are substituted with the filename and
# current line number in sncli's pager.
# If {fname} isn't supplied, the filename is simply appended.
# examples:
cfg_editor = nvim {fname} +{line}
cfg_editor = nano +{line}

# this is also supported for the pager:
cfg_pager = less -c +{line} -N {fname}

Editing notes

The flow sncli uses for editing notes is:

  1. create temporary file
  2. load the note contents into it
  3. launch the editor with the file
  4. wait for the editor to exit
  5. load the file contents into the internal note

As a result, the note doesn't get updated in sncli until the editor is closed. By default, the temporary file is created in the OS default tempdir (eg. /tmp/ on Linux). This can be changed with the cfg_tempdir option. This may be useful to create temporary files on a persistent file system to avoid data loss. For example:

cfg_tempdir = /home/user/.sncli/tmp/

This directory must exist.

Note that currently sncli does not clean up the tempfiles. This is to avoid the possibility of unrecoverable data loss in the case where sncli crashes between editing a note and saving or syncing the note. If using the OS default tempdir, these should be deleted upon reboot. If using a persistent tempdir, one should clean them up periodically to avoid too many files cluttering the system. For convenience, all tempfiles are created with the name prefix sncli-temp-<timestamp>-.

Note Title Format

The format of each line in the note list is driven by the cfg_format_note_title config item. Various formatting tags are supported for dynamically building the title string. Each of these formatting tags supports a width specifier (decimal) and a left justification (-) like that supported by printf:

  %F - flags (fixed 5 char width)
       X - needs sync
       T - trashed
       * - pinned
       S - published/shared
       m - markdown
  %T - tags
  %D - date
  %N - title

The default note title format pushes the note tags to the far right of the terminal and left justifies the note title after the date and flags:

cfg_format_note_title = '[%D] %F %-N %T'

Note that the %D date format is further defined by the strftime format specified in cfg_format_strftime.

Colors

sncli utilizes the Python Uwrid module to implement the console user interface.

At this time, sncli does not yet support 256-color terminals and is limited to just 16-colors. Color names that can be specified in the .snclirc file are listed here.

Searching

sncli supports two styles of search strings. First is a Google style search string and second is a Regular Expression.

A Google style search string is a group of tokens (separated by spaces) with an implied AND between each token. This style search is case insensitive. For example:

/tag:tag1 tag:tag2 word1 "word2 word3" tag:tag3

Regular expression searching also supports the use of flags (currently only case-insensitive) by adding a final forward slash followed by the flags. The following example will do a case-insensitive search for something:

(regex) /something/i

Creating from command line

# create a new note and open in editor
sncli create

# create a new note with contents of stdin
echo 'hi' | sncli create -

Importing

sncli can import notes from raw json data (via stdin or editor). For example:

echo '{"tags":["testing","new"],"content":"New note!"}' | sncli import -

Allowed fields are content, tags, systemTags, modificationDate, creationDate, 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.

Tags

Note tags can be modified directly from the command line. Example:

# Retrieve note tags, as one comma-separated string (e.g. "tag1,tag2")
sncli -k somekeyid tag get                  # Returns "tag1,tag2"

# Add a tag to a note, if it doesn't already have it
sncli -k somekeyid tag add "tag3"           # Now tagged as "tag1,tag2,tag3"

# Remove a tag from a note
sncli -k somekeyid tag rm "tag2"            # Now tagged as "tag1,tag3"

# Overwrite all of the tags for a note
sncli -k somekeyid tag set "tag2,tag4"      # Now tagged as "tag2,tag4"

Note that in SimpleNote, tags are case-insensitive, so "TAG2", "tag2", and "tAg2" are interpreted as the same and will all be converted to lowercase.

Tricks

I personally store a lot of my notes in Votl/VimOutliner format. Specific to Vim, I put a modeline at the end of these notes (note that Emacs also supports modelines):

; vim:ft=votl

Now when I edit this note Vim will automatically load the votl plugin. Lots of possibilities here...

Note: more tips and tricks on the GitHub wiki!

Microsoft Windows support

There is partial Windows support:

  • WSL and Cygwin versions of Python work
  • Native Windows support is limited:
    • batch/command line like sync and view work
    • UI interaction does not work BUT can be made to partially work via a monkey patch to Urwid (see urwid/urwid#447)
    • See #119 for details

Thanks

This application pulls in and uses the simplenote.py module by mrtazz and the notes_db.py module from nvpy by cpbotha.

sncli's People

Contributors

1094 avatar ashiklom avatar clach04 avatar djhsu avatar gregwebs avatar insanum avatar lostways avatar matthiaskauer avatar pataquets avatar plaindocs avatar retrography avatar shawnaxsom avatar volt4ire avatar vrillusions avatar wyattwalter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sncli's Issues

Google style search is case sensitive on tags?

I have just started using this wonderful program, with help from you all, and hope to make it a main part of my workflow.

One small issue has appeared. The README.md says that google style search is case insensitive. But it appears to be case sensitive when searching tags. I am not able to attach a screenshot (Github keeps saying "Something went really wrong") but I am able to reproduce this.

Is there any way of toggling a case insensitive search, or of making that the default?

Thanks again!

Can't login to simplenote anymore. [provide more meaningful errors]

sncli won't login to simplenote for me now. Nothing has changed on sncli's side, so I suspect Simplenote has changed its API.

I get the following in the log:

2016-12-31 15:41:36,336 [DEBUG] sncli logging initialized
2016-12-31 15:41:37,466 [DEBUG] Sync worker: started
2016-12-31 15:41:37,467 [DEBUG] Starting full sync
2016-12-31 15:41:37,470 [INFO] Starting new HTTPS connection (1): simple-note.appspot.com
2016-12-31 15:41:37,992 [DEBUG] "POST /api/login HTTP/1.1" 400 0

I'll look into it as soon as I get time, but in the meantime, interested to see if anyone else has this problem as well?

Piping is not working

Hi,
I am trying to pipe content to another program using the | key.

From within a note, I get the following traceback. I typed "cat" in the input field that appears on the bottom after pressing |.

Traceback (most recent call last):                                                                                                                                               
  File "/home/matt/venv/sncli/bin/sncli", line 11, in <module>
    sys.exit(main())
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1244, in main
    sncli(sync, verbose, config).gui(key)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1032, in gui
    self.sncli_loop.run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/container.py", line 1587, in keypress
    key = self.focus.keypress(tsize, key)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/user_input.py", line 22, in keypress
    self.callback_func(self.callback_func_args, self.edit_text)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 395, in gui_pipe_input
    pipe.communicate(note['content'])
  File "/usr/lib/python3.5/subprocess.py", line 1057, in communicate
    self._stdin_write(input)
  File "/usr/lib/python3.5/subprocess.py", line 1012, in _stdin_write
    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'

Also tried "echo" on a note from the list or index viewer. Similar result.

(sncli) x AD99W matt@hp840:~/venv $ sncli
Traceback (most recent call last):
  File "/home/matt/venv/sncli/bin/sncli", line 11, in <module>
    sys.exit(main())
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1244, in main
    sncli(sync, verbose, config).gui(key)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1032, in gui
    self.sncli_loop.run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/urwid/container.py", line 1587, in keypress
    key = self.focus.keypress(tsize, key)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/user_input.py", line 22, in keypress
    self.callback_func(self.callback_func_args, self.edit_text)
  File "/home/matt/venv/sncli/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 395, in gui_pipe_input
    pipe.communicate(note['content'])
  File "/usr/lib/python3.5/subprocess.py", line 1057, in communicate
    self._stdin_write(input)
  File "/usr/lib/python3.5/subprocess.py", line 1012, in _stdin_write
    self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'

I am running sncli in a virtualenv with Python 3.5 on Linux Mint 18.2 Xfce 64-bit.

Can you make sense of that?
Best regards,
Matthias

Start editor in the currently highlighted line

Hi,
when switching from note view to editor, I'd like the editor to start in the correct line.

I have taken a look at the code and it appears to me that lb.focus_position needs to be passed along to exec_cmd_on_note. For vim, the command to execute would be something like vim <fname> +<line>. Ideally, that could be encoded in the config so the style of other editors is also possible.

Do you have any thoughts on this?

Best regards,
Matthias

BTW: What's your workflow for copying things from one note to another? Do you open sncli twice? Is that safe?

Command line tag API

Syntax like this would be cool.

sncli tag set <key> "tag1"   # Note would be tagged with "tag1"
sncli tag get <key>   # Returns "tag1"
sncli tag set <key> "tag2"   # Note would be tagged with just "tag2"
sncli tag add <key> "tag3"   # Note would now be tagged as "tag2,tag3"
sncli tag rm <key> "tag2"    # Note would now be tagged as "tag3"

This could be implemented in stages:

  • sncli tag get -- Retrieve the tag string.
  • sncli tag set -- Modify the entire tag string.
  • sncli tag add -- Add a tag. After the other two, should just be a simple string concatenation.
  • sncli tag rm -- Remove a tag. Should just be a string substitution.

I can take a stab at implementing this.

sncli create - error

When i try to create a note i get this error

Traceback (most recent call last):
File "/home/moritz/.local/bin/sncli", line 11, in
sys.exit(main())
File "/home/moritz/.local/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 1379, in main
sn.cli_note_create(False, title)
File "/home/moritz/.local/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 1113, in cli_note_create
content = self.exec_cmd_on_note(None)
File "/home/moritz/.local/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 99, in exec_cmd_on_note
focus_position = self.gui_body_get().focus_position
File "/home/moritz/.local/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 227, in gui_body_get
return self.master_frame.contents['body'][0]
AttributeError: 'sncli' object has no attribute 'master_frame'

Spacebar as keybinding

Is there any way to bind spacebar to a function with the current configuration files?

Issue with + sign

Hi there,

Loving sncli but facing an issue: it seems as least the + sign is escaped/replaced by a blank space when sending to SN. To reproduce:

  • create a new note in sncli with a + sign
  • synch
  • check the note from another SN client or the SN web interface

Notes created from other clients or from the SN web interface keep the + sign.

This makes sncli unsuitable to store e.g. code snippets or ASCII-armored PGP blobs.

Notes deleted from disk locally after updating to new python3 update, 100 notes remain

Hi @swalladge. Thanks for your efforts on the unicode issue and for keeping sncli development moving!

I will try to dive into debugging this further at some point, or understanding the new python3 code.

Quick question for now: is there a new synchronization and local caching strategy in place with the new python3 code, to only cache 100 notes locally?

Note: I have a large 1500 note database, and use Notational Velocity (nvALT) on other platforms for research notes.

So, earlier this week when I tested the python3 branch on swalladge/sncli, before you merged the python3 commits with insanum/sncli master, I noticed that a large number of notes (actually all notes looking at the log files again) were deleted as soon as the python3 instance was launched. It appeared that only 100 notes were synced and saved to disk, from apparently arbitrary time frames.

I also tried initializing a brand new .sncli local database with the python3 code, with the same result (100 seemingly arbitrary notes are synced and saved to disk).

I tabled the issue and didn't report it on your fork, as I thought it might just be something unique to my environment or your fork, and I saw that you were going to unfork.

However, this morning, I tried again after updating to the new python3 code at the head on insansum/sncli master, and the same behavior was observed.

I'll try to debug further later.

Meanwhile, I have reverted to commit d0e75dd on insansum/sncli with a fresh first-time sync, and all is well in python2 sncli land. : )

[1] FWIW: to the log

2016-05-27 00:30:26,136 [DEBUG] Full sync completed  # pre-python3
2016-05-27 00:32:23,172 [DEBUG] sncli logging initialized # first python3 initialization
2016-05-27 00:32:26,417 [DEBUG] Sync worker: started
2016-05-27 00:32:26,418 [DEBUG] Starting full sync
2016-05-27 00:32:26,480 [INFO] Starting new HTTPS connection (1): simple-note.appspot.com
2016-05-27 00:32:26,859 [DEBUG] Setting read timeout to None
2016-05-27 00:32:26,942 [DEBUG] "POST /api/login HTTP/1.1" 200 64
2016-05-27 00:32:26,966 [INFO] Starting new HTTPS connection (1): simple-note.appspot.com
2016-05-27 00:32:27,242 [DEBUG] Setting read timeout to None
2016-05-27 00:32:27,349 [DEBUG] "GET /api2/index?auth=<>&length=<>&email=<>HTTP/1.1" 200 20896
2016-05-27 00:32:27,459 [DEBUG] Deleted note from disk (key=<>.... #followed by >1500 Deleted note from disk messages

Crashing with TypeError unorderable types on first run in Debian

Thank you for all the work on this program!

I'm trying to get it installed in a Debian Jessie system that mostly runs packages from the testing repository (i.e. all the Python packages are from there). With some difficulty I managed to install it using pip3 install sncli (I had to separately install the python3-wheel, python3-urwid, python3-request and python3-setuptools packages to get it to even try to start).

I then created .snclirc and tried to run from my home directory. I get a white bar at the top of the terminal saying 'Simplenote" and then the program crashes with this stack trace:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/notes_db.py", line 632, in sync_worker
    self.sync_now(do_server_sync)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/notes_db.py", line 625, in sync_now
    full_sync=True if not self.last_sync else False)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/notes_db.py", line 428, in sync_notes
    self.log("Starting full sync")
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 258, in log
    self.log_timeout, None)
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 165, in set_alarm_in
    return self.event_loop.alarm(sec, cb)
  File "/usr/lib/python3/dist-packages/urwid/main_loop.py", line 604, in alarm
    heapq.heappush(self._alarms, (tm, callback))
TypeError: unorderable types: function() < function()

Though this error occurs in the urwid module, it occurs whether I use the version from pip (pip3 install urwid) or from Debian (both testing and unstable repositories). So it seems like the error is in the code for sncli.

No one else seems to have this problem - have I done something wrong while installing the program? I'd love to use this.

sncli crashes with TypeError: unorderable types: function() < function()

Problem:

  • When I first installed sncli (via pip3), everything worked beautifully.
  • After a reboot, when invoking sncli, it pops up, I'm able to move around and enter a note, but perhaps 2-3 seconds in I get an error. Afterwards, all key presses don't do anything and I have to ctrl-C out of sncli.
  • Is this a Windows 7-related issue? I've had no problems running sncli under ubuntu.

Environment:

  • cygwin (32bit) in cygterm (Windows 7)
  • Python 3.4.5

Error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 911, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 859, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.4/site-packages/simplenote_cli/notes_db.py", line 632, in sync_worker
    self.sync_now(do_server_sync)
  File "/usr/lib/python3.4/site-packages/simplenote_cli/notes_db.py", line 625, in sync_now
    full_sync=True if not self.last_sync else False)
  File "/usr/lib/python3.4/site-packages/simplenote_cli/notes_db.py", line 428, in sync_notes
    self.log("Starting full sync")
  File "/usr/lib/python3.4/site-packages/simplenote_cli/sncli.py", line 258, in log
    self.log_timeout, None)
  File "/usr/lib/python3.4/site-packages/urwid/main_loop.py", line 165, in set_alarm_in
    return self.event_loop.alarm(sec, cb)
  File "/usr/lib/python3.4/site-packages/urwid/main_loop.py", line 604, in alarm
    heapq.heappush(self._alarms, (tm, callback))
TypeError: unorderable types: function() < function()

Note directory?

Hi, is there a way of making sncli sync all notes for offline use in a directory? Thanks!

crash on first startup when trying to take a note

$ pip3 install sncli
...
$ sncli # then press C to take a new note
sncli database doesn't exist, forcing full sync...
Starting full sync
ERROR: Failed to get note list from server
Full sync completed
Traceback (most recent call last):
  File "/home/user/.local/bin/sncli", line 11, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1343, in main
    sncli(sync, verbose, config).gui(key)
  File "/home/user/.local/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 1046, in gui
    self.sncli_loop.run()
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "/home/user/.local/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/home/user/.local/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/home/user/.local/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/user/.local/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 627, in gui_frame_keypress
    content = self.exec_cmd_on_note(None)
  File "/home/user/.local/lib/python3.5/site-packages/simplenote_cli/sncli.py", line 99, in exec_cmd_on_note
    'line': self.gui_body_get().focus_position + 1,
  File "/home/user/.local/lib/python3.5/site-packages/urwid/listbox.py", line 591, in _get_focus_position
    raise IndexError("No focus_position, ListBox is empty")
IndexError: No focus_position, ListBox is empty

disable log footer/automatic syncing

I've been using sncli for a while, and one thing is really starting to annoy me: when I use it offline, the program is constantly trying to connect to the simplenote server, triggering the log which makes the footer pop up, and in the process, distracting me. This could be rectified with a number of different features:

  • user-triggered syncing (press s to sync or something)
  • an option to disable automatic syncing (or maybe sncli understanding that the internet is disconnected)
  • an option to disable the log footer

Data recovery if crash during saving

I experienced data loss today. I edited a note with vim, saved and quit, and when I came back to sncli, the UI was frozen. I quit sncli with Ctrl+C and my edit was lost.

This should never happen, there should be some sort of data recovery mechanism that ensures that after I have saved the file in vim, I can be sure not to lose its contents. I've lost data in the past due to my computer running out of battery while still editing the note (despite having saved it).

How to protect the password in config file

Hi,

Thanks for creating this great little tool.

I'm trying to figure out a way to encrypt the password info in .snclirc file.
I had some experiences in encrypting the password for mutt config so I tried doing the same by first creating a file containing:

[sncli]
cfg_sn_username = [email protected]
cfg_sn_password = mypassword

Then encrpt it using gpg, giving an encrypted file password.gpg.

Then in ~/.snclirc, I put

source "gpg -d ~/.sncli/password.gpg |"

Running sncli gives this error:

Traceback (most recent call last):
  File "/usr/bin/sncli", line 11, in <module>
    load_entry_point('sncli==0.2.0', 'console_scripts', 'sncli')()
  File "/usr/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 1343, in main
    sncli(sync, verbose, config).gui(key)
  File "/usr/lib/python3.6/site-packages/simplenote_cli/sncli.py", line 18, in __init__
    self.config         = Config(config_file)
  File "/usr/lib/python3.6/site-packages/simplenote_cli/config.py", line 128, in __init__
    self.configs_read = cp.read([os.path.join(self.home, '.snclirc')])
  File "/usr/lib/python3.6/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/usr/lib/python3.6/configparser.py", line 1080, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/home/guangzhi/.snclirc', line: 1
'source "gpg -d ~/.sncli/password.gpg |"\n'

I guess the python configparser is not recognizing the source command.

I got around this by creating an alias:

alias sncli="gpg -d ~/.sncli/password.gpg > ~/.snclirc && sncli"

I guess aliasing is not recursive in bash so it seems to be working. But this prevents me from adding other configs in .snclirc because using >> instead of >, I will get a duplicate error.

What do you think will be my best way out? Maybe add a prompt if the password is not given in the config file?

Thanks

Starting sncli while disconnected from network results in all notes being deleted from disk.

Starting sncli while disconnected from network results in all notes being deleted from disk.

The README speaks of two-way sync, so offline operation support was the expected behavior, with two-way sync once network connectivity was re-established. Are off-line operations not supported? If not supported currently, is off-line support planned in the future?

2014-09-11 17:51:37,475 [DEBUG] sncli logging initialized
2014-09-11 17:51:38,748 [DEBUG] Sync worker: started
2014-09-11 17:51:38,760 [DEBUG] Starting full sync
2014-09-11 17:51:38,777 [DEBUG] ERROR: Failed to get note list from server
2014-09-11 17:51:38,791 [DEBUG] Deleted note from disk (key=...)
...

Search using cyrillic(unicode?) characters cause crash

How to reproduce:
open sncli
type command: /фото
program crashed
Traceback (most recent call last):
File "./sncli", line 33, in
sncli.main(sys.argv[1:])
File "/home/igor/prj/sncli/sncli/simplenote_cli/sncli.py", line 1200, in main
sncli(sync).gui(key)
File "/home/igor/prj/sncli/sncli/simplenote_cli/sncli.py", line 1016, in gui
self.sncli_loop.run()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 278, in run
self.screen.run_wrapper(self._run)
File "/usr/lib64/python2.7/site-packages/urwid/raw_display.py", line 272, in run_wrapper
return fn()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 343, in _run
self.event_loop.run()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 673, in run
self._loop()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 710, in _loop
self._watch_filesfd
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 394, in _update
self.process_input(keys)
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 494, in process_input
k = self._topmost_widget.keypress(self.screen_size, k)
File "/usr/lib64/python2.7/site-packages/urwid/container.py", line 1583, in keypress
key = self.focus.keypress(tsize, key)
File "/home/igor/prj/sncli/sncli/simplenote_cli/user_input.py", line 22, in keypress
self.callback_func(self.callback_func_args, self.edit_text)
File "/home/igor/prj/sncli/sncli/simplenote_cli/sncli.py", line 340, in gui_search_input
self.view_titles.update_note_list(search_string, args[0])
File "/home/igor/prj/sncli/sncli/simplenote_cli/view_titles.py", line 23, in update_note_list
self.ndb.filter_notes(self.search_string, search_mode)
File "/home/igor/prj/sncli/sncli/simplenote_cli/notes_db.py", line 96, in filter_notes
self.filter_notes_gstyle(search_string)
File "/home/igor/prj/sncli/sncli/simplenote_cli/notes_db.py", line 218, in filter_notes_gstyle
self._helper_gstyle_wordmatch(word_pats, n.get('content')):
File "/home/igor/prj/sncli/sncli/simplenote_cli/notes_db.py", line 145, in _helper_gstyle_wordmatch
if wp in lowercase_content:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

note nvpy work fine with unicode search...

Cannot create a new note

On OS X 10.10.2, when creating a new note I save and quit vim and the note is not saved.
There is no error in the log file.

Support for internal links

Hi,
I'm a relatively new user and maybe this feature already exists or doesn't make sense.
Every once in a while it makes sense to refer from one note to another note.
nvpy allows this using [[..]].

Example:

Kotlin libraries
Also see [[Java libraries]]

Clicking on [[x]] effectively populates the search bar with x.
Is something like that feasible and useful in sncli?

Best regards,
Matthias

Support for Emacs as editor (SOLVED)

First, thanks for the software. I have a great affinity to many CLI tools, and glad to see feature - rich implementaion.

One request, how much work needed to replace VI with emacs?

Thanks

Oleg

Filter/search tags (and maybe have a tag menu)

First off, great application! I use it all the time, and it's the happiest I've been with a note application in a while.

I did have two related requests though:

  1. Would it be possible to implement searching only tags? Some of my tags happen to be common words, so when I search for them, I get all the notes with that tag and all the notes that have the tag somewhere in their content.

  2. Building on that -- Simplenote has a nice clickable list of tags that lets you filter notes to only a single tag. Would it be possible to implement a similar menu in sncli? E.g. ctrl-shift-t opens a full-screen list of all tags, and hitting enter (or something) on one of the tags lists all notes restricted to that tag.

work on python 2.x

its great it works on python 3, can we get it to be compatible with python 2.7.x as the majority of *nix users are still on it?

sync_worker RuntimeError: maximum recursion depth exceeded

During sync, at some point long after the screen has completely filled with "Synced new note from server (key=...)" log messages (another issue), the following traceback appears, ending with "RuntimeError: maximum recursion depth exceeded."

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/site-packages/simplenote_cli/notes_db.py", line 615, in sync_worker
    self.sync_now(do_server_sync)
  File "/usr/lib/python2.7/site-packages/simplenote_cli/notes_db.py", line 608, in sync_now
    full_sync=True if not self.last_sync else False)
  File "/usr/lib/python2.7/site-packages/simplenote_cli/notes_db.py", line 532, in sync_notes
    self.log('Synced new note from server (key={0})'.format(k))
  File "/usr/lib/python2.7/site-packages/simplenote_cli/sncli.py", line 237, in log
    self.gui_footer_log_set(log_pile)
  File "/usr/lib/python2.7/site-packages/simplenote_cli/sncli.py", line 158, in gui_footer_log_set
    self.sncli_loop.draw_screen()
  File "/usr/lib/python2.7/site-packages/urwid/main_loop.py", line 565, in draw_screen
    canvas = self._topmost_widget.render(self.screen_size, focus=True)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 141, in cached_render
    canv = fn(self, size, focus=focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1058, in render
    (maxcol, maxrow), focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1022, in frame_top_bottom
    self.focus_part=='footer' and focus)
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 201, in cached_rows
    return fn(self, size, focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1568, in rows
    return sum(self.get_item_rows(size, focus))
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1470, in get_item_rows
    focus=focus and self.focus_item == w))
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 201, in cached_rows
    return fn(self, size, focus)
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1568, in rows
    return sum(self.get_item_rows(size, focus))
...
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1568, in rows
    return sum(self.get_item_rows(size, focus))
  File "/usr/lib/python2.7/site-packages/urwid/container.py", line 1470, in get_item_rows
    focus=focus and self.focus_item == w))
  File "/usr/lib/python2.7/site-packages/urwid/widget.py", line 201, in cached_rows
    return fn(self, size, focus)
RuntimeError: maximum recursion depth exceeded

Error on creating a note.

I'm having an error now on creating my first note. This is on ubuntu 12.04. I set cfg_editor = vi (which is vim-tiny). I also installed urwid with pip install urwid as discussed in #19. Version now is:

> pip --version urwid
pip 1.0 from /usr/lib/python2.7/dist-packages (python 2.7)

When I use "C" to create a note, all seems well util I save the note using :wq, which is what I assume I should do when I want to return out of vim into the sncli interface, correct? The error produced (notice the "t" in "traceback" is missing in the output, that's not my copy/paste error) is:

raceback (most recent call last): when manual pages are not available.
  File "/usr/local/bin/sncli", line 33, in <module>
    sncli.main(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 1200, in main
    sncli(sync).gui(key)D] [COMMAND_ARGS]
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 1016, in gui
    self.sncli_loop.run()
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 278, in run
    self._run()               - verbose output
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 375, in _run
    self.event_loop.run()     - search string is a regular expression
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 678, in run
    self._loop()title=<title> - title of note for create (cli mode)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 715, in _loop
    self._watch_files[fd]()
  File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 392, in <lambda>
    event_loop, callback, self.get_available_raw_input())the server
  File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 492, in parse_input
    callback(processed, processed_codes)es (refined with search string)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 399, in _update
    self.process_input(keys)  - dump a note (specified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 499, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)ified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 612, in gui_frame_keypress
    self.gui_update_view()>   - markdown/unmarkdown a note (specified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 265, in gui_update_view
    cur_key = self.view_titles.note_list[self.view_titles.focus_position].note['key']
KeyError: 'key' 

Is this another problem with an old version of urwid?

Terminal corruption

Sometimes when logs are being presented at the bottom of the terminal, the body section gets corrupted. The corruption quickly goes away when urwid refreshes the screen. Need to figure out if this is a python/urwid/sncli issue or a terminal issue.

Add a license

I think it's important to projects to have a license. Consider MIT. It's a good license.

Ubuntu 12.04. Error on first run.

Hi. I'm running Ubuntu 12.04 with python 2.7 and python-urwid installed. I ran "sudo python setup.py install" to do the install and then made a ~/.snclirc with a dummy account name. When I run "sncli -n", I get the following error. I don't know any python, but it looks like some problem with urwid? Thoughts?

sncli -n
Traceback (most recent call last):
  File "/usr/local/bin/sncli", line 33, in <module>
    sncli.main(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 1200, in main
    sncli(sync).gui(key)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 920, in gui
    'log'           : self.log
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/view_titles.py", line 18, in __init__
    urwid.SimpleFocusListWalker(self.get_note_titles()))
AttributeError: 'module' object has no attribute 'SimpleFocusListWalker'

Thanks,
/DA

crash on edit

hi, sncli crashes when I press e for edit. On ubuntu 14.04, 64bit.

Viewer encoder crash while parsing "smart quote" and "smart dash" unicode characters

Do we need to spread the new unicode goodness further throughout the code base? If so, I could help dig into this later. Not urgent from my p.o.v.

Just opening this as a new issue as my comment in #23 seems to be unresolved so far by the latest python3 commits, as apparently this "Viewer open with unicode character" case is different than the #23 "Search with unicode characters" case.

Issue summary: The viewer crashes when parsing lines with "smart quote" open/close unicode quote character (e.g., \u2014), which is a common occurrence in any corpus originally sourced from a rich text editor.

UnicodeEncodeError: 'ascii' codec can't encode character '\u2014'

...
  File "/usr/lib/python3/dist-packages/urwid/canvas.py", line 1291, in apply_text_layout
    text[s.offs:s.end])
  File "/usr/lib/python3/dist-packages/urwid/util.py", line 121, in apply_target_encoding
    s = s.encode( _target_encoding )
UnicodeEncodeError: 'ascii' codec can't encode character '\u2014' in position 17: ordinal not in range(128)

if you want to configure 'cfg_pager' to show formatted markdown files

  1. install mdv
  2. make a wrapper /usr/local/sbin/mdless
    #!/bin/zsh
    # https://superuser.com/questions/1059781/what-exactly-is-in-bash-and-in-zsh
    /usr/bin/less -R -c =(mdv "$1")
    # /usr/bin/less -R -c =(mdv -A "$1") # light background (not yet supported)
  3. set it in ~/.snclirc
    cfg_pager = /usr/local/sbin/mdless
    

Can't create new notes

Problem:
I can't make new entries neither with sncli create or with the console GUI when pressing 'C'. In the GUI I get only a screen refresh when I try creating a note or even when I am trying to edit one.

Other functions like sncli list, sncli sync and sncli export are working fine, and I can see my notes as well.

Environment:

  • Python 3.5.2
  • Linux and Bash
  • Urwid and Requests installed

Error:

~$ sncli -t Title create "Something"
~$ sncli create Test

No error in both, only the usage text. Is that the correct way to make a note through stdin?

~$ sncli edit <a key listed by sncli list>

No error as well.

~$ sncli create

Traceback (most recent call last):
  File "/usr/local/bin/sncli", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 1371, in main
    sn.cli_note_create(False, title)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 1105, in cli_note_create
    content = self.exec_cmd_on_note(None)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 99, in exec_cmd_on_note
    'line': self.gui_body_get().focus_position + 1,
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 219, in gui_body_get
    return self.master_frame.contents['body'][0]
AttributeError: 'sncli' object has no attribute 'master_frame'

When I am invoking sncli from emacs I get the same error.

(defun sncli-forward-buffer ()
  "Sends the current buffer as stdin to sncli and making a new entry in simplenote." 
  (interactive)
  (shell-command-on-region (point-min) (point-max) "sncli create ")
  (message "Buffer saved in  simplenote."))
Traceback (most recent call last):
  File "/usr/local/bin/sncli", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 1371, in main
    sn.cli_note_create(False, title)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 1105, in cli_note_create
    content = self.exec_cmd_on_note(None)
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 99, in exec_cmd_on_note
    'line': self.gui_body_get().focus_position + 1,
  File "/usr/local/lib/python3.5/dist-packages/simplenote_cli/sncli.py", line 219, in gui_body_get
    return self.master_frame.contents['body'][0]
AttributeError: 'sncli' object has no attribute 'master_frame'

Am I missing something in my config file? I only have my username and password in it.
Or maybe something is outdated?

No urwid?

I had to pip install urwid... On Mac OS X 10.10.

CLI should return failing status when something doesn't work

Hi,
I am trying to use sncli as a backup solution for simplenotes in addition to the main browsing/editing which is already going ok.

I can use sncli export the entire database to json just fine. However, I noticed that when I remove my credentials file, sncli export or sncli sync still succeed from a bash point of view.

Inside sncli, I get: "status 400, check credentials". But from the command line, it looks as follows:

matt@hp840:~/venv $ sncli sync
matt@hp840:~/venv $ echo $?
0

From my understanding, the program should return 1 (or not 0) in such a situation.
What do you think?

Best regards,
Matthias

Logging should be configurable

Currently logging is hardcoded at the DEBUG level. This should be configurable via the cli and/or config file. This would allow a clean log that only has errors for normal usage, and full debug logging when testing/developing.

Also related, we don't really want the auth token in the logs - this shows since it seems requests is logging all the network requests at DEBUG level (and the sn auth token is present in the get params).

Sync Understandings,

Thank you! for sncli,

I would like to clear up my understanding of Syncing, I only see Syncing of the note I am working in with Simplenote when I use wq and not with w, nor wa, is this right,

Thanks,

Switch to pipenv

I feel it would be useful to drop the requirements.txt and switch to using a Pipfile for a better developer experience. Thoughts?

Little UTF8 display issue

UTF-8 support in the content (notes) is fine, this is just about the display in urwid, so I'm not sure this really is a cncli bug.

Using Terminal.app or iTerm2.app on Mac OS, accented characters display as ? in the index or pager views (to clarify, they're fine when opening for editing in vim, and notes created in sncli with accented characters are also fine in other SN clients, it really is just about the display).

E.g. éàèù

'UTF-8' problem

When edit the file which content has "UTF-8" charset, something wrong:

...
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 499, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 615, in gui_frame_keypress
    content = self.exec_cmd_on_note(note)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 81, in exec_cmd_on_note
    tf = temp.tempfile_create(note if note else None, raw=raw)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/temp.py", line 21, in tempfile_create
    tf.write(note['content'])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-5: ordinal not in range(128)

I did a quick patch for myself.
Without much more testing.
Hope it will works well for other guys ;)

 simplenote_cli/sncli.py |    8 ++++----
 simplenote_cli/temp.py  |    4 ++--
 2 个文件被修改,插入 6 行(+),删除 6 行(-)

diff --git simplenote_cli/sncli.py simplenote_cli/sncli.py
index 0e76a91..bcac3db 100644
--- simplenote_cli/sncli.py
+++ simplenote_cli/sncli.py
@@ -623,8 +623,8 @@ class sncli:
             if not content:
                 return None

-            md5_old = md5.new(note['content']).digest()
-            md5_new = md5.new(content).digest()
+            md5_old = md5.new(note['content'].encode("utf-8")).digest()
+            md5_new = md5.new(content.encode("utf-8")).digest()

             if md5_old != md5_new:
                 self.log(u'Note updated')
@@ -1030,8 +1030,8 @@ class sncli:
         if not content:
             return

-        md5_old = md5.new(note['content']).digest()
-        md5_new = md5.new(content).digest()
+        md5_old = md5.new(note['content'].encode("utf-8")).digest()
+        md5_new = md5.new(content.encode("utf-8")).digest()

         if md5_old != md5_new:
             self.log(u'Note updated')
diff --git simplenote_cli/temp.py simplenote_cli/temp.py
index 46de9c2..f81968f 100644
--- simplenote_cli/temp.py
+++ simplenote_cli/temp.py
@@ -18,7 +18,7 @@ def tempfile_create(note, raw=False):
             ext = '.mkd'
         tf = tempfile.NamedTemporaryFile(suffix=ext, delete=False)
         if note:
-            tf.write(note['content'])
+            tf.write(note['content'].encode("utf-8"))
         tf.flush()
     return tf

@@ -35,6 +35,6 @@ def tempfile_content(tf):
     tf.seek(0)
     lines = []
     for line in tf:
-        lines.append(line)
+        lines.append(line.decode("utf-8"))
     return lines

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.