February 07, 2015

Flask & Mongo for Wedding RSVPs

One of the few things I’ve been able to help my fiancée with during wedding planning has been the wedding website.

Being a somewhat technological couple, we decided to forgo paper RSVP response cards and instead ask that our guests respond online. Some services like RSVPify exist for just this purpose, but what’s the fun in that. Rolling my own allowed for very tight coupling with the user experience of our wedding website.

The github repo has the full flask application. Currently, some summary statistics of the current rsvp status are supported. The static content of the website is all hosted with Github Pages and the RSVP functionality interacts with a REST interface defined in Flask hosted by DigitalOcean.

I found a nifty shell script by Andrea Fabrizi called dropbox-uploader.sh which, as the name implies, uses the Dropbox API to upload files given as arguments. Using this, I was able to automate mongodb backups of the latest RSVP data with the following

#!/bin/bash

DATE=$(date +%Y-%m-%d-%H-%M)

pushd /tmp
mongodump -d jr_web -o jr-mongo-$DATE
tar pczf jr-mongo-$DATE.tar.gz jr-mongo-$DATE
rm -rf jr-mongo-$DATE
/home/db/dropbox_uploader.sh upload jr-mongo-$DATE.tar.gz jr-mongo-$DATE.tar.gz
rm -f jr-mongo-$DATE.tar.gz
popd

With this, I simply use cron to upload a backup every few hours. This allows me to test in production and not worry too much about making any fatal mistakes.