这是我的完整工作代码:
import os
import sys
import hashlib
import binascii
from datetime import datetime,timedelta
import logging
# sys.path.append("lib")
# sys.path.append("libs/evernote-sdk-python3")
sys.path.append("libs/evernote-sdk-python3/lib")
from evernote import *
from evernote.api import *
from evernote.api.client import *
from evernote.edam.limits import *
from evernote.edam.type import *
from evernote.edam.type.ttypes import *
from evernote.edam.notestore import *
from evernote.edam.notestore.ttypes import *
from evernote.edam.notestore.NoteStore import *
from evernote.edam.userstore import *
from evernote.edam.userstore.constants import *
ToProcessNotebook = "toProcess"
isSandbox=True
# isChina=False
isChina=True
AuthTokenDict = {
"sandbox": {
# China, https://sandbox.evernote.com/api/DeveloperToken.action
"yinxiang": "change_to_your_token",
# International
"evernote": "",
},
"production": {
"yinxiang": "",
"evernote": "",
},
}
ServiceHost = ""
AuthToken = ""
if isChina:
if isSandbox:
AuthToken = AuthTokenDict["sandbox"]["yinxiang"]
ServiceHost = "sandbox.yinxiang.com"
else:
AuthToken = AuthTokenDict["production"]["yinxiang"]
ServiceHost = "app.yinxiang.com"
else:
if isSandbox:
AuthToken = AuthTokenDict["sandbox"]["evernote"]
ServiceHost = "sandbox.evernote.com"
else:
AuthToken = AuthTokenDict["production"]["evernote"]
ServiceHost = "app.evernote.com"
gClient = None
gUserStore = None
gNoteStore = None
def init():
global gClient, gUserStore, gNoteStore
logFilename = "EvernoteToWordpress_%s.log" % (getCurDatetimeStr())
loggingInit(logFilename)
gClient = EvernoteClient(
token=AuthToken,
# sandbox=sandbox,
# china=china,
service_host=ServiceHost
)
logging.info("gClient=%s", gClient)
gUserStore = gClient.get_user_store()
logging.info("gUserStore=%s", gUserStore)
isVersionOk = gUserStore.checkVersion(
"Evernote EDAMTest (Python)",
EDAM_VERSION_MAJOR, # UserStoreConstants.EDAM_VERSION_MAJOR,
EDAM_VERSION_MINOR, # UserStoreConstants.EDAM_VERSION_MINOR
)
logging.info("Is my Evernote API version up to date? %s", isVersionOk)
gNoteStore = gClient.get_note_store()
logging.info("gNoteStore=%s", gNoteStore)
def EvernoteToWordpress():
"""Process evernote note into wordpress"""
global gClient, gUserStore, gNoteStore
notebookList = gNoteStore.listNotebooks()
notebookListLen = len(notebookList)
logging.info("Found %s notebooks:", notebookListLen)
for curNotebook in notebookList:
logging.info("\tguid=%s,name=%s", curNotebook.guid, curNotebook.name)
if curNotebook.name == ToProcessNotebook:
processNotes(curNotebook)
break
def processNotes(curNotebook):
"""Process each note"""
logging.info("curNotebook=%s", curNotebook)
# find all notes in notebook
searchOffset = 0
searchPageSize = 100
searchFilter = NoteStore.NoteFilter()
searchFilter.order = NoteSortOrder.UPDATED
searchFilter.ascending = False
searchFilter.notebookGuid = curNotebook.guid
logging.info("searchFilter=%s", searchFilter)
resultSpec = NotesMetadataResultSpec()
resultSpec.includeTitle = True
resultSpec.includeContentLength = True
resultSpec.includeCreated = True
resultSpec.includeUpdated = True
resultSpec.includeDeleted = True
resultSpec.includeNotebookGuid = True
resultSpec.includeTagGuids = True
resultSpec.includeAttributes = True
resultSpec.includeLargestResourceMime = True
resultSpec.includeLargestResourceSize = True
logging.info("resultSpec=%s", resultSpec)
# foundNoteResult = gNoteStore.findNotesMetadata(
# authenticationToken=AuthToken,
# filter=searchFilter,
# offset=searchOffset,
# maxNotes=pageSize,
# resultSpec=resultSpec
# )
foundNoteResult = gNoteStore.findNotesMetadata(AuthToken, searchFilter, searchOffset, searchPageSize, resultSpec)
logging.info("foundNoteResult=%s", foundNoteResult)
if __name__ == "__main__":
init()
EvernoteToWordpress()
注意:evernote sdk 是从Evernote SDK for Python 3下载的
最新代码:crifanEvernote.py