Last active
February 3, 2023 01:14
-
-
Save drcharris/603c197bbdfe57a058d3 to your computer and use it in GitHub Desktop.
Fetch Evernote notes from a notebook using javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); //async library to allow macro-wokr over async methods | |
var Evernote = require('evernote').Evernote; //the evernote client | |
var _ = require('lodash'); //handy utility function | |
/** | |
* @param token the authorisation token returned from your Evernote authentication | |
* @param bookGuid the unique identifier of the notebook | |
*/ | |
function getNotesFromEvernote(token, bookGuid) { | |
//an evernote client object | |
var client = new Evernote.Client({ | |
token: token, | |
sandbox: true | |
}); | |
//curried async function to fetch a given note. notestore is Evernote.Client.getNoteStore() | |
//https://dev.evernote.com/doc/reference/NoteStore.html#Fn_NoteStore_getNote | |
function getNote(notestore) { | |
return function(guid, cb) { | |
notestore.getNote(guid, true, false, false, false, function (err, note) { | |
if (err) cb(err, null); | |
else cb(null, _.omit(note, 'contentHash')); //remove contentHash element as it's big and not needed | |
}); | |
}; | |
} | |
//we search for notes via a NoteFilter, specifying simply the guid of the notebook we want to | |
//look at | |
var filter = new Evernote.NoteFilter(); | |
filter.notebookGuid = bookGuid; | |
//the resultspec is used to specify what Evernote should return - we leave this empty so we get | |
//everything possible back in a single call | |
var spec = new Evernote.NotesMetadataResultSpec(); | |
var store = client.getNoteStore(); | |
//first, find note metadata using the search criteria above | |
store.findNotesMetadata(filter, 0, 1000, spec, function(err, notes) { | |
if(err) console.log(err); | |
else { | |
//second actually GET the notes by applying the getNotes returned function to each note guid | |
async.map(_.pluck(notes.notes, 'guid'), getNote(store), function(err, results) { | |
if(err) console.log(err); | |
else { | |
//DO SOMETHING WITH 'results' HERE | |
} | |
}); | |
} | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment