Skip to content
Browse files

Fixed function that allows edit note in the editor.

  • Loading branch information...
1 parent 8c1a767 commit ead81ed8124b8df4e6cf88959efd35c5e5dbdeda Родненко Виталий committed
Showing with 16 additions and 46 deletions.
  1. +16 −46 geeknote.py
View
62 geeknote.py
@@ -123,43 +123,18 @@ def createNote(self, title, text):
return self.noteStore.createNote(self.authToken, note)
- def editNote2(self, name, full):
- io.preloader.stop()
- note = self.getNote(name, full)
- EDITOR = os.environ.get('EDITOR','nano')
- """
- with tempfile.NamedTemporaryFile(suffix=".txt") as tmpfile:
- tmpfile.write(str(note.content))
- tmpfile.flush()
- call([EDITOR, tmpfile.name])
- for line in tmpfile.readlines():
- print line
- tmpfile.close()
- """
-
- tmpfile = tempfile.NamedTemporaryFile(mode='w+t', delete=False, suffix=".html")
- tmpfile.write(html2text.html2text(str(note.content)))
- tmpfile.flush()
- n = tmpfile.name
- tmpfile.close()
- call([EDITOR, n])
- newfile = open(n)
- newnote = newfile.read()
- newfile.close()
- os.remove(n)
- #self.createNote("New", newnote)
-
- return 1
-
def _convertToHTML(self, note):
noteHTML = markdown.markdown(note)
return noteHTML
def _parseNoteToMarkDown(self, note):
- txt = html2text.html2text(note.decode('utf-8','ignore'))
- return txt#.decode('utf-8', 'replace')
+ txt = html2text.html2text(note.decode('us-ascii','ignore'))
+ return txt.decode('utf-8', 'replace')
def _wrapNotetoHTML(self, noteBody):
+ """
+ Create an ENML format of note.
+ """
mytext = '''<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd">
<en-note>'''
mytext += self._convertToHTML(noteBody)
@@ -167,42 +142,39 @@ def _wrapNotetoHTML(self, noteBody):
return mytext
def editNote(self, noteid):
+ """
+ Call the system editor, that types as a default in the system.
+ Editing goes in markdown format, and then the markdown converts into HTML, before uploading to Evernote.
+ """
+
note = self.getNote(noteid, noteid)
io.preloader.stop()
- """
- note = Types.Note()
- note = self.getNote(self.noteName, False)
- """
oldNote = self._parseNoteToMarkDown(note.content)
(fd, tfn) = tempfile.mkstemp()
os.write(fd, oldNote)
os.close(fd)
+ # Try to find default editor in the system.
editor = os.environ.get("editor")
if not (editor):
editor = os.environ.get("EDITOR")
if not (editor):
+ # If default editor is not finded, then use nano as a default.
editor = "nano"
+ # Make a system call to open file for editing.
os.system(editor + " " + tfn)
file = open(tfn, 'r')
contents = file.read()
-
- print contents
-
- #noteContent = self._wrapNotetoHTML(contents)
- #note.content = noteContent
- #self.noteStore.updateNote(self.authToken, note)
-
-
- return
try:
+ # Try to submit changes.
noteContent = self._wrapNotetoHTML(contents)
note.content = noteContent
self.noteStore.updateNote(self.authToken, note)
except:
+ # If it's an error.
print "Your XML was malformed. Edit again (Y/N)?"
answer = ""
while (answer.lower() != 'n' and answer.lower() != 'y'):
@@ -224,6 +196,4 @@ def getInput():
gn = GeekNote()
-gn.getNoteStore()
-#print gn.getAllNotes(10)
-print gn.editNote("Test")
+gn.getNoteStore()

0 comments on commit ead81ed

Please sign in to comment.
Something went wrong with that request. Please try again.