Permalink
Browse files

Added code to move notes from one notebook to another. Some refactori…

…ngs to eliminate duplication uncovered by its creation.
  • Loading branch information...
1 parent dfffa4a commit 6cfe4ec794139e673382a265cc317de95c8d59f5 @HotFusionMan committed Jul 12, 2009
Showing with 100 additions and 112 deletions.
  1. +25 −5 Evernote_connection.rb
  2. +1 −11 de-duplicate_Evernote_notes.rb
  3. +1 −0 linkify.rb
  4. +26 −94 linkify_Evernote_notes.rb
  5. +46 −0 move_note_to_notebook.rb
  6. +1 −2 post_Evernote_note.rb
@@ -47,14 +47,34 @@
noteStoreProtocol = Thrift::BinaryProtocol.new(noteStoreTransport)
@noteStore = Evernote::EDAM::NoteStore::NoteStore::Client.new(noteStoreProtocol)
-notebooks = @noteStore.listNotebooks( @authToken )
-#puts "Found #{notebooks.size} notebooks:"
-@defaultNotebook = notebooks[0]
-notebooks.each { |notebook|
+@notebooks = @noteStore.listNotebooks( @authToken )
+#puts "Found #{@notebooks.size} notebooks:"
+@defaultNotebook = @notebooks[0]
+@notebooks.each { |notebook|
# puts " * #{notebook.name}"
if (notebook.defaultNotebook)
@defaultNotebook = notebook
end
}
-MAX_INT32 = 2**31 - 1
+MAX_INT32 = 2**31 - 1
+
+
+def get_all_notes_from_default_notebook
+ get_all_notes_from_notebook( @defaultNotebook.guid )
+end
+
+def get_all_notes_from_notebook( notebook_guid )
+ filter = Evernote::EDAM::NoteStore::NoteFilter.new
+ filter.notebookGuid = notebook_guid
+ filter.order = Evernote::EDAM::Type::NoteSortOrder::CREATED
+ filter.ascending = TRUE
+
+ begin
+ noteList = @noteStore.findNotes( @authToken, filter, 0, 10000 ) # Evernote doesn't like using big numbers here such as MAX_INT32 )
+ return noteList.notes
+ rescue => e
+ puts "Error occurred : #{e.errorCode}"
+ exit
+ end
+end
@@ -2,17 +2,7 @@
require 'Evernote_connection'
-filter = Evernote::EDAM::NoteStore::NoteFilter.new
-filter.notebookGuid = @defaultNotebook.guid
-filter.order = Evernote::EDAM::Type::NoteSortOrder::CREATED
-filter.ascending = TRUE
-
-begin
- noteList = @noteStore.findNotes( @authToken, filter, 0, 10000 ) # Evernote doesn't like using big numbers here such as MAX_INT32 )
-rescue => e
- puts e #.message
- exit
-end
+noteList = get_all_notes_from_default_notebook
have_seen_note_title = {}
View
@@ -4,6 +4,7 @@
@starts_with_ftp_regexp = Regexp.new( '(^|[\n (\[{])((ftp)\.[^ \"\t\n\r<]*)', Regexp::MULTILINE | Regexp::IGNORECASE )
@email_regexp = Regexp.new( '(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)', Regexp::IGNORECASE )
+# NOTE: The linkify operation is not idempotent. Do not run it on text that has already been linkified!
def linkify( text )
s = text.to_s
s.gsub!( @generic_URL_regexp, '\1<a href="\2">\2</a>' )
@@ -1,102 +1,34 @@
# Written for de-duplication of notes created from Twitter favorites
require 'Evernote_connection'
+require 'rexml/document'
+require 'post_Evernote_note'
+require 'linkify'
-noteList = get_all_notes_from_default_notebook
-notes = noteList.notes
+notes = get_all_notes_from_default_notebook
-max_index = 1
notes.each_with_index { |note, i|
- note.struct_fields.each_value { |value|
- name = value[:name]
- puts "#{name}=#{note.send( name )}"
- }
- puts
- break if i >= max_index
-}
+ # note.struct_fields.each_value { |value|
+ # name = value[:name]
+ # puts "#{name}=#{note.send( name )}"
+ # }
-=begin
-==
-===
-=~
-__id__
-__send__
-active
-active=
-attributes
-attributes=
-class
-clone
-content
-content=
-contentHash
-contentHash=
-contentLength
-contentLength=
-created
-created=
-deleted
-deleted=
-differences
-display
-dup
-each_field
-eql?
-equal?
-extend
-fields_with_default_values
-freeze
-frozen?
-guid
-guid=
-hash
-id
-inspect
-instance_eval
-instance_of?
-instance_variable_defined?
-instance_variable_get
-instance_variable_set
-instance_variables
-is_a?
-kind_of?
-method
-methods
-name_to_id
-nil?
-notebookGuid
-notebookGuid=
-object_id
-private_methods
-protected_methods
-public_methods
-read
-resources
-resources=
-respond_to?
-send
-singleton_methods
-struct_fields
-tagGuids
-tagGuids=
-taguri
-taguri=
-taint
-tainted?
-title
-title=
-to_a
-to_s
-to_yaml
-to_yaml_properties
-to_yaml_style
-type
-untaint
-updateSequenceNum
-updateSequenceNum=
-updated
-updated=
-validate
-write
-=end
+ xml_document = REXML::Document.new( @noteStore.getNoteContent( @authToken, note.guid ) )
+ content_node = xml_document.root.get_elements( '//en-note' ).first
+ content = content_node.text
+
+ updated_note = Evernote::EDAM::Type::Note.new
+ updated_note.guid = note.guid
+ updated_note.title = note.title
+ updated_note.content = build_Evernote_note_content( linkify( content ) )
+ updated_note.created = note.created
+ updated_note.updated = Time.now.to_i * 1000
+
+ begin
+ updated_note_metadata = @noteStore.updateNote( @authToken, updated_note )
+ puts "Note was updated, GUID = #{updated_note_metadata.guid}"
+ rescue Thrift::Exception => e
+ puts "Error occurred on note with GUID #{note.guid} : #{e.errorCode}"
+ end
+}
@@ -0,0 +1,46 @@
+require 'Evernote_connection'
+
+def move_note_to_notebook( note_guid, notebook_guid )
+ begin
+ note = @noteStore.getNote( @authToken, note_guid, FALSE )
+ rescue => e
+ puts "Error occurred on note with GUID #{note_guid} : #{e.errorCode}"
+ end
+
+ note.notebookGuid = notebook_guid
+
+ begin
+ updated_note = @noteStore.updateNote( @authToken, note )
+ rescue => e
+ puts "Error occurred on note with GUID #{note_guid} : #{e.errorCode}"
+ end
+end
+
+
+# file_name = 'problem_GUIDs.txt'
+#
+# File.open( file_name ) { |file|
+# file.each_line { |line|
+# guid = line.chomp
+#
+# move_note_to_notebook( guid, @defaultNotebook.guid )
+# }
+# }
+
+
+
+source_notebook_guid = nil
+@notebooks.each { |notebook|
+ if notebook.name == 'Twitter favorites linkified' then
+ source_notebook_guid = notebook.guid
+ end
+}
+
+unless source_notebook_guid.nil?
+ defaultNotebook_guid = @defaultNotebook.guid
+
+ notes = get_all_notes_from_notebook( source_notebook_guid )
+ notes.each { |note|
+ move_note_to_notebook( note.guid, defaultNotebook_guid )
+ }
+end
@@ -23,8 +23,7 @@ def post_to_Evernote( note_title, well_formed_XHTML_note_content )
createdNote = @noteStore.createNote( @authToken, note )
puts "Note was created, GUID = #{createdNote.guid}"
rescue Thrift::Exception => e
- puts e.message
- raise
+ puts "Error occurred on note with GUID #{note.guid} : #{e.errorCode}"
end
end

0 comments on commit 6cfe4ec

Please sign in to comment.