Get note information using Evernote SDK for Python 3

Overview

--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

About Evernote SDK for Python 3

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. ..

Library installation

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

Sample code to get note information

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}')

Sample execution example

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

Reference material

Recommended Posts

Get note information using Evernote SDK for Python 3
boto3 (AWS SDK for Python) Note
Python script to get note information with REAPER
Authentication information used by Boto3 (AWS SDK for Python)
Get GitHub information using PyGithub
3 months note for starting Python
Get Evernote notes in Python
Get Alembic information with Python
Try a similar search for Image Search using the Python SDK [Search]
Python Note: About comparison using is
[TouchDesigner] Tips for for statements using python
[Python] Reasons for overriding using super ()
[Python] Multiplication table using for statement
Python Note: Get the current month
Get weather information with Python & scraping
Effective Python Note Item 17 Respect for certainty when using iterators for arguments
[Python] I tried to get various information using YouTube Data API!
Get property information by scraping with python
Notes for using OpenCV on Windows10 Python 3.8.3.
Python> dictionary> values ()> Get All Values by Using values ()
Get Suica balance in Python (using libpafe)
Get tweets containing keywords using Python Tweepy
[50 counts] Key transmission using Python for Windows
Get metadata for existing tables using SQLAlchemy
Note for Pyjulia calling Julia from Python
[python, multiprocessing] Behavior for exceptions when using multiprocessing
Using Azure ML Python SDK 5: Pipeline Basics
Note: Python
Working with OpenStack using the Python SDK
Get Youtube data in Python using Youtube Data API
Tips for using python + caffe with TSUBAME
[python] Get Twitter timeline for multiple users
Get a token for conoha in python
Python note
Notes for using python (pydev) in eclipse
[Python] Get Python package information with PyPI API
A useful note when using Python for the first time in a while
GUI display train delay information using python
vprof --I tried using the profiler for Python
Python for super beginners Python for super beginners # Easy to get angry
[Python] Get all comments using Youtube Data API
Python pandas: Search for DataFrame using regular expressions
Upgrade the Azure Machine Learning SDK for Python
Get image URL using Flickr API in Python
Device driver to get CPU information for ARM
Refined search for Pokemon race values using Python
Note for formatting numbers with python format function
GCP Key Management Service + Python for secret information management
Get information about videos uploaded to YouTube [Python]
Get CPU information of Raspberry Pi with Python
Get BTC / JPY board information from Python --bitflyer
Let's make a module for Python using SWIG
Call Polly from the AWS SDK for Python
2016-10-30 else for Python3> for:
Note: Python Decorator
Python programming note
[Python] Learning Note 1
Get an Access Token for your service account with the Firebase Admin Python SDK
Python study note_004
Start using Python
Python study note_003