Engineering The Simple Postcard

April 20, 2016
Written by

PostcardFeatured

Jason Strauss’ debugging took a week. His input was familiar — code. The output was uncharted analog territory – a postcard. Unlike your 500 error, a postcard takes a week to get back to you. Jason was debugging in week-long chunks.

After a few weekends of work, discovering the perfect NLP library for him, and gluing together three APIs, The Simple Postcard was born. Send a photo you want made into a postcard, enter an address, and pay all via text.

It’s all text-based So don’t ask Jason if he’ll build an app. He’ll answer your question with another, “Why should people have to install something?”

Home Is Where Your Localhost Is, Or Wherever You Can Send Postcards

When Jason and his girlfriend were long distance they sent letters to each other. Having a tactile message as opposed to a digital one was alluring. But, the “user interface” for sending letters, The United States Postal Service, does not offer the most enjoyable experience.

The Simple Postcard was a product of equal parts intrigue and necessity. In building the service, Jason learned how to use a few new tools. The stack behind The Simple Postcard is Django, PostgreSQL, VQL, Lob, Stripe, Twilio, USAddress, and Bootstrap.

Unraveling Strings

A key component of The Simple Postcard’s stack is a Python library called US Address Parser that uses NLP to convert the raw address strings to the components of the address. This separates a block of text into city, street, zipcode etc. Then Jason’s app passes that info to Lob, a print API, who takes care of the postcard manufacturing. The app uses the Twilio MMS API to store and pass that image that’s printed on the card.

Here’s the code that TSP executes when someone sends in a photo to start a new postcard.

# Sample code from TheSimplePostcard.com
# TechStack: Django, PostgreSQL, VQL, Twilio, Lob, Stripe, Bootstrap, usaddress

# If theres an image, then start a new postcard
if num_media > 0:
  img = params.get("MediaUrl"+str(int(num_media)-1)) # get the last picture

  new_postcard = Postcard(
    from_number = from_number,
    raw_img_src = img,
    postcard_status = 'image_added'
  )
  new_postcard.save()

  # and ask them for the address
  response_text = 'Got it! Who would you like to send that to, name and address? (eg. %s)' % RandomSampleAddress()
  return RespondToText(response_text)

And when Jason is feeling gracious, this is the code he uses to send a random card for free.

# Sample code from TheSimplePostcard.com
# TechStack: Django, PostgreSQL, VQL, Twilio, Lob, Stripe, Bootstrap, usaddress

# Occasionally, we choose to ship a card for free
import datetime, random
def FreeCard():
  die_1 = random.randint(1, 6)
  die_2 = random.randint(1, 6)
  current_month = datetime.datetime.now().month
  return (die_1 + die_2) == current_month

 

Getting A Reply

Jason’s already gotten some great feedback after hitting the top spot on HackerNews this week. “TSP received really great feedback on HN. I’ve also received really nice feedback from mothers and girlfriends, like ‘literally made my whole day,’ which I rarely hear about my code.”

So now when the postcard you made, ordered, and paid for via text arrives at your door, you might think a week turnaround time is pretty fast after all.

Check out Jason’s full-time project GetVQL, right here. Grab his code on GitHub here