3

我已经像这样设置了我的 Python 页面(摘录):

import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient

client = EvernoteClient(token=auth_token, sandbox=False)
note_store = client.get_note_store()

问题来自此代码:

filter = note_store.NoteFilter
filter.setOrder(NoteSortOrder.UPDATED.getValue())

然后我会继续使用 note_store.findNotesMetadata。但是,我收到错误:

AttributeError: 'module' object has no attribute 'setOrder'

我究竟做错了什么?我试图适应这里给出的例子

4

2 回答 2

7

这是一个工作示例:

from evernote.api.client import EvernoteClient
from evernote.edam.notestore.ttypes import NoteFilter, NotesMetadataResultSpec
from evernote.edam.type.ttypes import NoteSortOrder

auth_token = 'your-token'
client = EvernoteClient(token=auth_token)
note_store = client.get_note_store()

updated_filter = NoteFilter(order=NoteSortOrder.UPDATED)
offset = 0
max_notes = 10
result_spec = NotesMetadataResultSpec(includeTitle=True)
result_list = note_store.findNotesMetadata(auth_token, updated_filter, offset, max_notes, result_spec)

# note is an instance of NoteMetadata
# result_list is an instance of NotesMetadataList
for note in result_list.notes:
    print note.title
于 2013-08-31T05:29:16.737 回答
0

这是我的完整工作代码:

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

于 2019-11-30T13:15:14.903 回答