Module: Everdone

Defined in:
lib/everdone/enmlformatter.rb,
lib/everdone.rb,
lib/everdone/sync.rb,
lib/everdone/config.rb,
lib/everdone/todoist.rb,
lib/everdone/version.rb,
lib/everdone/evernote.rb,
lib/everdone/todoItem.rb

Overview

Class to help create the ENML (EverNote Markup Language) content

Defined Under Namespace

Classes: Config, EnmlFormatter, Evernote, Sync, TodoItem, TodoNote, Todoist

Constant Summary collapse

VERSION =
"0.0.32"

Class Method Summary collapse

Class Method Details

.get_notebook_from_project(project) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/everdone.rb', line 25

def self.get_notebook_from_project(project)
    notebook = @@config.todoist_evernote_map[project]  # It is possible the project is in the map but the value is nil.  This means: don't add items from this project to Evernote
    if not @@config.todoist_evernote_map.has_key?(project)  # If the project is not in the map at all then put it in the default notebook
        notebook = @@config.default_notebook
    end
    return notebook
end

.initObject



19
20
21
22
23
# File 'lib/everdone.rb', line 19

def self.init
    @@config = Config.new(File.expand_path("../everdone/default_config.json", __FILE__), "#{Dir.home}/.everdone")
    @@evernote = Evernote.new(@@config)
    @@todoist = Todoist.new(@@config)
end

.syncObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/everdone.rb', line 33

def self.sync
    self.init
    
    sync = Sync.new(@@config, @@todoist)

    items = @@todoist.get_completed_items()
    puts "INFO: Returned #{items.length} items"
    processed = []  # list of Todoist item ids that were processed
    found = []  # list of Todoist item ids not in the already processed list but subsequently found in Evernote
    excluded = [] # a list of Todoist item ids that were not added because they belong to a project that is blacklisted
    items.each { |item|
        if not sync.is_already_processed(item.id)
            # Map the project to an Evernote notebook
            notebook = get_notebook_from_project(item.projects[0])
            find_count = @@evernote.find_note_counts("#{@@config.}#{item.id}", notebook) if notebook
            if notebook.nil?
                excluded.push(item.id)  # project did not map to any notebook => don't add to Evernote
            elsif find_count > 0
                found.push(item.id)  # Todoist item already in Evernote => don't add
            else  # not already processed nor in an ignored project nor was it found in Evernote.  Make a new one!
                # Create the note's content
                content = EnmlFormatter.new(@@config)
                content.text("Project: ").link(item.projects[0], item.get_project_url(0))
                if item.labels.length > 0
                    content.space.space.space.space
                    content.text("Labels: ")
                    item.labels.each { |label| 
                        content.link(label, item.get_label_url(label)).space 
                    }
                end
                content.space.space.space.text("#{@@config.}#{item.id}")
                item.notes.each { |note|  
                    content.h3("Note created #{content.datetime_to_string(note.created, @@config.todoist_datetime_format)}   [Todoist note id: #{note.id}]")
                    content.rawtext(note.content)
                }

                # Create the note in Evernote
                @@evernote.create_note(item.title, 
                    content.to_s, 
                    notebook,
                    Evernote.convert_text_to_timestamp(item.created, @@config.todoist_datetime_format))
            end
            processed.push(item.id)  # whether item was added to Evernote or not don't process it again.
        end
    }

    # Finish up by doing the syncing bookwork
    sync.close(processed)

    puts "INFO: Done! Of #{items.length} found..."
    puts "  #{processed.length - (found.length+excluded.length)} added to Evernote"
    puts "  #{found.length} were already in Evernote" if found.length > 0
    puts "  #{excluded.length} were not added as they are in blacklisted Todoist projects" if excluded.length > 0
    puts "  All time total processed now #{sync.get_processed_total()}"
end