Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Last active August 29, 2015 14:01
Show Gist options
  • Save Kwpolska/45f7b84194a046f4f15c to your computer and use it in GitHub Desktop.
Save Kwpolska/45f7b84194a046f4f15c to your computer and use it in GitHub Desktop.
PerpeTask evernote experiment
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# The PerpeTask Evernote experiment
# Copyright © 2014, Chris “Kwpolska” Warrick.
# All rights reserved.
# Licensed under the BSD license.
"""The PerpeTask Evernote experiment."""
from evernote.api.client import EvernoteClient
with open('DEV_TOKEN', 'r') as fh:
dev_token = fh.read().strip()
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
noteStore = client.get_note_store()
nb = noteStore.listNotebooks()
for n in nb:
if n.name == 'To-do lists':
T = n
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:5a0ff661c9d4ac79ef0217cbb5ad4d53e93c280409411aa9ec1af42d1fcab9a7"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PerpeTask Evernote Experiment\n",
"\n",
"Set the contents of the oldest note to something worthless."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# imports\n",
"from A_PerpeTask import *\n",
"import evernote.edam.notestore.ttypes as NSTypes"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Search.\n",
"# Create a filter.\n",
"nf = NSTypes.NoteFilter()\n",
"nf.notebookGuid = T.guid\n",
"# Createa result specification to include titles in the results.\n",
"spec = NSTypes.NotesMetadataResultSpec()\n",
"spec.includeTitle = True\n",
"# Run the search.\n",
"ml = noteStore.findNotesMetadata(dev_token, nf, 0, 100, spec)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ml.notes"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"[NoteMetadata(updated=None, created=None, deleted=None, contentLength=None, title='Thing One', notebookGuid=None, updateSequenceNum=None, tagGuids=None, largestResourceMime=None, attributes=None, guid='8d20e07e-8175-4c9d-8ee7-2c5401f28ae6', largestResourceSize=None),\n",
" NoteMetadata(updated=None, created=None, deleted=None, contentLength=None, title='Thing Two', notebookGuid=None, updateSequenceNum=None, tagGuids=None, largestResourceMime=None, attributes=None, guid='1ed743c1-339b-4b07-a445-e02a756adf76', largestResourceSize=None)]"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"#Get the first note we found.\n",
"TLN = noteStore.getNote(dev_token, ml.notes[0].guid, True, False, False, False)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Change the note.\n",
"TLN.content = \"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
"<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n",
"<en-note>\n",
"<div>1n! take 3</div>\n",
"<div><en-todo/>task 1</div>\n",
"<div><en-todo checked=\"true\"/>task 2</div>\n",
"</en-note>\"\"\"\n",
"TLN = noteStore.updateNote(TLN)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"TLN"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
"Note(contentHash='\\xf1\\xc5\\x0e\\xdb\\x05\\x86\\xc5\\x84\\xa4\\x04}\\xeb\\x88x^\\xa3', updated=1399117262000, created=1399117250000, deleted=None, contentLength=218, title='Thing One', notebookGuid='6790b9c2-0c98-40ae-8929-2da0f9aaecbd', content=None, tagNames=None, updateSequenceNum=22, tagGuids=None, active=True, attributes=NoteAttributes(lastEditorId=None, placeName=None, sourceURL=None, classifications=None, creatorId=None, author='kwpolska', reminderTime=None, altitude=None, reminderOrder=None, shareDate=None, reminderDoneTime=None, longitude=None, lastEditedBy=None, source=None, applicationData=None, sourceApplication=None, latitude=None, contentClass=None, subjectDate=None), guid='8d20e07e-8175-4c9d-8ee7-2c5401f28ae6', resources=None)"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment