def get_recipe(recipe, refresh): client = trace(get_client) notestore = trace(client.get_note_store) # Get the note metadata without a body or resources. This result contains # the body hash used for caching. partial = tracen('Evernote.note_store.getNote', notestore.getNote, recipe, False, False, False, False) # Check the cache for this note. key = '%s%s_%s' % (vmenu.app.config['CACHE_PREFIX'], binascii.hexlify(partial.contentHash), vmenu.app.config['RECIPE_IMAGES']) content = cache.get(key) if content is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key); else: logging.info('Cache miss for %s', key) full = tracen('Evernote.note_store.getNote', notestore.getNote, recipe, True, False, False, False) content = strip_tags(full.content.decode('utf-8')) def process(): url_prefix = trace(get_url_prefix) if full.resources is not None and vmenu.app.config['RECIPE_IMAGES']: for resource in full.resources: content = trace(update_resource, url_prefix, content, resource) trace(process) # Cache the content. The key is the MD5 hash of the server stored content # but the stored value in this cache has stripped out tags. cache.set(key, content, timeout=vmenu.app.config['CACHE_TIMEOUT']) return { "content": content }
def get_recipe(recipe, refresh): client = trace(get_client) notestore = trace(client.get_note_store) # Get the note metadata without a body or resources. This result contains # the body hash used for caching. partial = tracen('Evernote.note_store.getNote', notestore.getNote, recipe, False, False, False, False) # Check the cache for this note. key = '%s%s_%s' % (vmenu.app.config['CACHE_PREFIX'], binascii.hexlify(partial.contentHash), vmenu.app.config['RECIPE_IMAGES']) content = cache.get(key) if content is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key) else: logging.info('Cache miss for %s', key) full = tracen('Evernote.note_store.getNote', notestore.getNote, recipe, True, False, False, False) content = strip_tags(full.content.decode('utf-8')) def process(): url_prefix = trace(get_url_prefix) if full.resources is not None and vmenu.app.config['RECIPE_IMAGES']: for resource in full.resources: content = trace(update_resource, url_prefix, content, resource) trace(process) # Cache the content. The key is the MD5 hash of the server stored content # but the stored value in this cache has stripped out tags. cache.set(key, content, timeout=vmenu.app.config['CACHE_TIMEOUT']) return {"content": content}
def get_tags(refresh): key = vmenu.app.config['CACHE_PREFIX'] + 'tags' tags = cache.get(key) if tags is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key); else: logging.info('Cache miss for %s', key) client = trace(get_client) notestore = trace(client.get_note_store) notebook = trace(get_notebook, notestore, vmenu.app.config['NOTEBOOK']) tags = tracen('Evernote.note_store.listTagsByNotebook', notestore.listTagsByNotebook, notebook.guid) tags = sorted(tags, key = lambda Tag: Tag.name) cache.set(key, tags, timeout=vmenu.app.config['CACHE_TIMEOUT']) return tags
def get_tags(refresh): key = vmenu.app.config['CACHE_PREFIX'] + 'tags' tags = cache.get(key) if tags is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key) else: logging.info('Cache miss for %s', key) client = trace(get_client) notestore = trace(client.get_note_store) notebook = trace(get_notebook, notestore, vmenu.app.config['NOTEBOOK']) tags = tracen('Evernote.note_store.listTagsByNotebook', notestore.listTagsByNotebook, notebook.guid) tags = sorted(tags, key=lambda Tag: Tag.name) cache.set(key, tags, timeout=vmenu.app.config['CACHE_TIMEOUT']) return tags
def get_recipes(tag, refresh): key = vmenu.app.config['CACHE_PREFIX'] + 'recipes-' + tag results = cache.get(key) if results is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key) else: logging.info('Cache miss for %s', key) client = trace(get_client) notestore = trace(client.get_note_store) notebook = trace(get_notebook, notestore, vmenu.app.config['NOTEBOOK']) tag_guids = [tag] filter = NoteFilter(notebookGuid=notebook.guid, tagGuids=tag_guids) offset = 0 max_notes = 500 result_spec = NotesMetadataResultSpec(includeTitle=True) notes_result = tracen('Evernote.note_store.findNotesMetadata', notestore.findNotesMetadata, filter, offset, max_notes, result_spec) notes = sorted(notes_result.notes, key=lambda NoteMetadata: NoteMetadata.title) results = [] def process_notes(): url_prefix = trace(get_url_prefix) for n in notes: result = { 'guid': n.guid, 'title': n.title, 'thumbnail': trace(get_thumbnail, url_prefix, n.guid) } results.append(result) trace(process_notes) cache.set(key, results, timeout=vmenu.app.config['CACHE_TIMEOUT']) return results
def get_recipes(tag, refresh): key = vmenu.app.config['CACHE_PREFIX'] + 'recipes-' + tag results = cache.get(key) if results is None or refresh: if refresh: logging.info('Explicitly refreshing %s', key); else: logging.info('Cache miss for %s', key) client = trace(get_client) notestore = trace(client.get_note_store) notebook = trace(get_notebook, notestore, vmenu.app.config['NOTEBOOK']) tag_guids = [tag] filter = NoteFilter(notebookGuid=notebook.guid, tagGuids=tag_guids) offset = 0 max_notes = 500 result_spec = NotesMetadataResultSpec(includeTitle=True) notes_result = tracen('Evernote.note_store.findNotesMetadata', notestore.findNotesMetadata, filter, offset, max_notes, result_spec) notes = sorted(notes_result.notes, key = lambda NoteMetadata: NoteMetadata.title) results = [] def process_notes(): url_prefix = trace(get_url_prefix) for n in notes: result = { 'guid': n.guid, 'title': n.title, 'thumbnail': trace(get_thumbnail, url_prefix, n.guid) } results.append(result) trace(process_notes) cache.set(key, results, timeout=vmenu.app.config['CACHE_TIMEOUT']) return results
def get_notebook(notestore, name): for notebook in tracen('Evernote.note_store.listNotebooks', notestore.listNotebooks): if notebook.name == name: return notebook raise LookupError