Skip to content

Instantly share code, notes, and snippets.

@cyberhiker
Created October 12, 2015 15:23
Show Gist options
  • Save cyberhiker/f352b9d91804ac14d48f to your computer and use it in GitHub Desktop.
Save cyberhiker/f352b9d91804ac14d48f to your computer and use it in GitHub Desktop.
Automatically Creates Notes to Support Meal Planning and Grocery Shopping in Evernote
# Uploads a Grocery list Todo note and a Meal Plan formatted note
import datetime
import time
import sys
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
sys.path.append('evernote-sdk')
# Function that helps with title of Meal Plan and Reminder Setting
def nextWeekday(d, weekday):
days_ahead = weekday - d.weekday()
if days_ahead <= 0: # Target day already happened this week
days_ahead += 7
return d + datetime.timedelta(days_ahead)
# Get Evernote Ready with Auth and setting Note & User stores up
authToken = ''
client = EvernoteClient(token=authToken, sandbox=False)
noteStore = client.get_note_store()
userStore = client.get_user_store()
# Begin creating Grocery List
groceryNote = Types.Note()
# Set the Title
groceryNote.title = 'Grocery / Pharmacy'
# Set the destination notebook
groceryNote.notebookGuid = ''
# Generate note content
# The content of an Evernote note is represented using Evernote Markup
# Language (ENML). The full ENML specification can be found in the Evernote
# API Overview at
# http://dev.evernote.com/documentation/cloud/chapters/ENML.php
groceryNote.content = '<?xml version="1.0" encoding="UTF-8"?>'
groceryNote.content += '<!DOCTYPE en-note SYSTEM ' \
'"http://xml.evernote.com/pub/enml2.dtd">'
groceryNote.content += '<en-note>'
# Open a text file and add standard items that are needed every week
inputFile = open('GroceryListTemplate.txt')
try:
for i, line in enumerate(inputFile):
groceryNote.content += '<en-todo/>' + str(line) + '<br />'
finally:
inputFile.close()
groceryNote.content += '</en-note>'
groceryNote.content = groceryNote.content.encode('utf-8')
# End Creating Grocery List
# Begin Creating the Meal Plan
mealNote = Types.Note()
# Find out when Monday is so we can automatically set the Week Of in the title
nextMonday = nextWeekday(datetime.datetime.now(), 0) # 0 = Monday, 1=Tuesday, 2=Wednesday...
# Set the title
mealNote.title = 'Meal Plan for Week of %s-%s-%s' % (nextMonday.year, nextMonday.month, nextMonday.day)
# Set the destination notebook
mealNote.notebookGuid = ''
# Generate note content
# The content of an Evernote note is represented using Evernote Markup
# Language (ENML). The full ENML specification can be found in the Evernote
# API Overview at
# http://dev.evernote.com/documentation/cloud/chapters/ENML.php
mealNote.content = '<?xml version="1.0" encoding="UTF-8"?>'
mealNote.content += '<!DOCTYPE en-note SYSTEM ' \
'"http://xml.evernote.com/pub/enml2.dtd">'
mealNote.content += '<en-note>'
# Read formatted file that contains the meal plan
mealNote.content += open('MealPlanTemplate.htm').read()
mealNote.content += '</en-note>'
mealNote.content = mealNote.content.encode('utf-8')
# init NoteAttributes instance
mealNote.attributes = Types.NoteAttributes()
# Reminder Creation Stuff
thisSaturday = nextWeekday(datetime.datetime.now(), 5) # Get the date of the upcoming Saturday
saturday_at_8 = (datetime.datetime(thisSaturday.year, thisSaturday.month, thisSaturday.day, 9, 0)) # Set the time to 9am on the upcoming Saturday
saturday_at_8_milliseconds = time.mktime(saturday_at_8.timetuple()) * 1000 # Convert to Timestamp that Evernote can understan
mealNote.attributes.reminderTime = saturday_at_5_milliseconds
print "Uploading to Evernote..."
# Create the notes
createdGroceryNote = noteStore.createNote(groceryNote)
createdMealNote = noteStore.createNote(mealNote)
Avocados
Eating Fruit (Apples, Bananas, Strawberries, etc)
Onions
Garlic
Sweet Potatoes
Red Potatoes
Collard Greens
Whole Milk (2 Half Gallons)
Steel Cut Oats
Beans (Canned and Dried)
from evernote.api.client import EvernoteClient
dev_token = ""
client = EvernoteClient(token=dev_token, sandbox=False)
userStore = client.get_user_store()
user = userStore.getUser()
print user.username
noteStore = client.get_note_store()
allNotebooks = noteStore.listNotebooks()
for notebook in allNotebooks:
print notebook.name + " " + notebook.guid
noteGuid = "a05f2dac-7290-439c-afa5-8aa8065b010c"
note = noteStore.getNote(noteGuid, True, False, False, False)
<div>
<b>Sunday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Monday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Tuesday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Wednesday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Thursday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Friday</b> ()<br/>
<ul>
<li>Salmon</li>
<li>Couscous</li>
<li>Brussels Sprouts</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<div>
<b>Saturday</b> ()<br/>
<ul>
<li>Item</li>
</ul>
</div>
<br/>
<blockquote>
<div>
<u>Make Ahead</u><br/>
<ul>
<li>Item</li>
</ul><br/>
</div>
</blockquote>
<br/>
<b>Week Make Ahead</b><br/>
<ul>
<li>Bread</li>
<li>Yogurt</li>
<li>Other Items</li>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment