| View Comments ]


昨日取得了EverNote 的 API开发资料,看见有提供Python的api库自然欣喜若狂,不过偶这点水平也就只能拿它的sample来玩玩,并且还在考虑写份关于浏览器是否足以掌控一切的博文,可是最近真是烦透了,一点心思也没有。只是在博客中添加了较为好看的源代码显示效果,来欣赏一下,等偶有时间时再完成那篇[巨著],呵呵

import time
import thrift.transport.THttpClient as THttpClient
import thrift.protocol.TBinaryProtocol as TBinaryProtocol
import evernote.edam.userstore.UserStore as UserStore
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.notestore.NoteStore as NoteStore
import evernote.edam.type.ttypes as Types

#
# Configure these based on the API key you received from Evernote
#
consumerKey = ""
consumerSecret = ""
username = ""
password = ""

edamHost = "lb.evernote.com"
edamPort = 443

userStoreHttpClient = THttpClient.THttpClient(edamHost, edamPort, "/edam/user")
userStoreProtocol = TBinaryProtocol.TBinaryProtocol(userStoreHttpClient)
userStore = UserStore.Client(userStoreProtocol)

versionOK = userStore.checkVersion("Python EDAMTest",
                                   UserStoreConstants.EDAM_VERSION_MAJOR,
                                   UserStoreConstants.EDAM_VERSION_MINOR)

print "Is my EDAM protocol version up to date? ", str(versionOK)
if not versionOK:
    exit(1)

authResult = userStore.authenticate(username, password,
                                    consumerKey, consumerSecret)
user = authResult.user
authToken = authResult.authenticationToken
print "Authentication was successful for ", user.username
print "Authentication token = ", authToken
print userStore.getUser(authToken)
print userStore.getPublicUserInfo(username)

noteStoreUri = "/edam/note/" + user.shardId
noteStoreHttpClient = THttpClient.THttpClient(edamHost, edamPort, noteStoreUri)
noteStoreProtocol = TBinaryProtocol.TBinaryProtocol(noteStoreHttpClient)
noteStore = NoteStore.Client(noteStoreProtocol)

notebooks = noteStore.listNotebooks(authToken)
print "Found ", len(notebooks), " notebooks:"
for notebook in notebooks:
    print "  * ", notebook.name
    if notebook.defaultNotebook:
        defaultNotebook = notebook

print
print "Creating a new note in default notebook: ", defaultNotebook.name
print
note = Types.Note()
note.notebookGuid = defaultNotebook.guid
note.title = raw_input("Note title?  ").strip()
note.content = ''
note.content += ''
note.content += ''
note.content += raw_input("Well-formed XHTML note content?  ").strip()
note.content += ''
note.created = int(time.time() * 1000)
note.updated = note.created

createdNote = noteStore.createNote(authToken, note)

print "Created note: ", str(createdNote)


查看邮件也能赚钱 Iphone3G B 005 468x60


blog comments powered by Disqus