T Minus and Counting

Today I leave for vacation. This is the first time I’ve left the continent in more than 5 years. One of the best parts of planning a big trip is building anticipation leading up to the date. I took this anticipation and used it to try out the APIs for Alexa’s Flash Briefing, something I check every morning for my news podcasts.

Its very much a hack. The Alexa flash briefing it not so much an API as it is an RRS feed that you can push daily updates to. I didn’t want to set up a full RSS service just for the few weeks leading up to the trip so with some help from other blog posts I managed to use AWS Lambda behind an API gateway endpoint to mock out a bare bones RRS feed server. One that just decrements a number every day.

from __future__ import print_function
import json
import datetime

def respond(err, res=None):
 return {
 'statusCode': '400' if err else '200',
 'body': json.dumps({
 "uid": "1234",
 "updateDate": datetime.datetime.utcnow().isoformat() + 'Z',
 "titleText": str(days_to_trip()) + " days to vacation",
 "mainText": err.message if err else res['message'],
 "redirectionUrl": "https://yoururl.com"
 }),
 'headers': {
 'Content-Type': 'application/json',
 },
}

def days_to_trip():
 trip = datetime.datetime(2018,8,30,0,0,0,0,datetime.timezone.utc)
 today = datetime.datetime.now(datetime.timezone.utc)
 return (trip-today).days + 1

def lambda_handler(event, context):
 rawdata = "there are " + str(days_to_trip()) + " days until your trip to europe"
 reply = { "message": rawdata,
 }
 return respond(None, reply)

The date is hard coded the python is sloppy. But it did what I wanted, telling me every morning how many days I had left until my trip, and I was able to get it together in a couple of hours.

Soon they will start boarding for my flight and the adventure will start, the count down has reached zero.

One thought on “T Minus and Counting

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s