--Get Evernote note information using Evernote SDK for Python 3 --Environment: Python 3.8.5 + Evernote SDK for Python 3 (evernote3 package) 1.25.14 + macOS catalina
At this point (as of September 27, 2020), it's still experimental, and the official SDK for Python doesn't support Python 3.
GitHub - evernote/evernote-sdk-python3: Testing the Evernote Cloud API for Python 3
This is a test SDK! The official Evernote SDK for Python doesn't support Python 3 yet; this repository is an experiment as we try to migrate.
This SDK contains wrapper code used to call the Evernote Cloud API from Python.
The API Reference can be found in All Thrift declarations, but it is not for Python, so you may want to check the relevant part of the source code as well. ..
Install the Evernote SDK for Python 3.
$ pip install evernote3==1.25.14
You also need to install oauth2 (because it is not installed automatically due to dependencies).
$ pip install oauth2
from datetime import datetime, timezone, timedelta
#Use Evernote SDK for Python 3
from evernote.api.client import EvernoteClient
from evernote.edam.notestore.ttypes import NoteFilter, NotesMetadataResultSpec
# evernote.api.client.Initialize EvernoteClient
client = EvernoteClient(
token = 'YOUR_AUTH_ACCESS_TOKEN', #Specify access token
sandbox = False #Explicitly specify False when using a Production environment instead of a sandbox
)
# evernote.api.client.Get Store
store = client.get_note_store()
#Notebook evernote.edam.type.ttypes.Get a list of Notebooks
notebook_list = store.listNotebooks()
print(f'Number of notebooks: {len(notebook_list)}')
# evernote.edam.type.ttypes.Take out Notebook
for notebook in notebook_list:
print(f'Notebook name: {notebook.name}')
#Specify the conditions for the notes to be acquired
filter = NoteFilter()
filter.notebookGuid = notebook.guid #Specify the GUID of the notebook
#Set fields to include in NoteMetadata
spec = NotesMetadataResultSpec()
spec.includeTitle = True
spec.includeCreated = True
spec.includeAttributes = True
#List of note metadata evernote.edam.notestore.ttypes.Get NotesMetadataList
notes_metadata_list = store.findNotesMetadata(
filter,
0, #Specify the index position you want to get from the list that hits the offset condition
1, #maxNotes The maximum number of notes to retrieve. Get only one at most this time
spec)
print(f'Number of notes in the notebook: {notes_metadata_list.totalNotes}')
# evernote.edam.notestore.ttypes.Extract NoteMetadata
for note_meta_data in notes_metadata_list.notes:
print(f'Note title: {note_meta_data.title}')
# evernote.edam.type.ttypes.Get Note
note = store.getNote(
note_meta_data.guid, #Specify the GUID of the note
True, # withContent
True, # withResourcesData
True, # withResourcesRecognition
True) # withResourcesAlternateData
print(f'title: {note.title}')
print(f'Creation date and time: {datetime.fromtimestamp(note.created / 1000, timezone(timedelta(hours=9)))}')
print(f'Contents(XHTML): {note.content[0:64]}') #Since it is long, only the first 64 characters are extracted
#Extract media file information embedded or attached to a memo
if note.resources is not None:
# evernote.edam.type.ttypes.Extract Resource
for resource in note.resources:
print(f'Attached data file name: {resource.attributes.fileName}')
print(f'data type: {resource.mime}')
Save the sample code as my_notes.py and run it.
$ python my_notes.py
Number of notebooks: 4
Notebook name: Todoist
Number of notes in the notebook: 6
Note title: Completed Todoist Tasks
title: Completed Todoist Tasks
Creation date and time: 2017-09-02 09:43:19+09:00
Contents(XHTML): <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "
Notebook name:Voice data
Number of notes in the notebook: 5
Note title:Japanese syllabary message
title:Japanese syllabary message
Creation date and time: 2016-08-14 20:03:58+09:00
Contents(XHTML): <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE
Attached data file name:AIUEO.m4a
data type: audio/x-m4a
Notebook name: webclip
Number of notes in the notebook: 2
Note title:Sample page
title:Sample page
Creation date and time: 2015-03-19 17:34:03+09:00
Contents(XHTML): <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE
Attached data file name: None
data type: image/jpeg
Attached data file name: None
data type: image/png
Notebook name:Technical data storage
Number of notes in the notebook: 15
Note title:Hackathon material
title:Hackathon material
Creation date and time: 2018-02-23 15:26:58+09:00
Contents(XHTML): <?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE
Attached data file name: IMG_2741.HEIC
data type: image/jpeg
Attached data file name: IMG_2618.HEIC
data type: image/jpeg
Recommended Posts