What's New With WhisperGifts

Posted by Ross Poulton on Sun 24 August 2014 #django #whispergifts

In the past couple of months I've done some fun and interesting stuff over at WhisperGifts, my side project that lets couples put their bridal gift registry online. It's all built with Django, so I thought I'd share a few neat things I've come across along the way.

Bookmarket and image detection

For a while I've had a bookmarklet to add any item to your registry, which basically took the page title, selected text (or meta description), and URL and pre-filled the Add Item form. Recently, I updated it to also find the largest image on the page, and add that as the default image for the item you selected.

This makes it pretty quick to add an item from, for example, an Amazon page or a manufacturer's website. The code to do it was surprisingly simple. Apologies for the short variable names; this is taken directly from my bookmarklet code so brevity is a plus in that scenario.

var ims=document.getElementsByTagName('img');
var imsMxD=0;
var im='';
for(x=0;x<ims.length;x++){
    var xDim=parseFloat(ims[x].width)*parseFloat(ims[x].height);
    if((xDim>imsMxD)&&(ims[x].src)){
        imsMxD=xDim;
        im=ims[x].src;
    }
}

This will give me a variable, im, which contains the URL of the largest image on the page. I then pass this to the form to pre-populate the image field. It's a really easy way to find the largest image on the page (in this case, taken as the largest surface area) and then do something useful with it.

Updated HTML and Pricing

I rebuilt WhisperGifts marketing site and dashboard using Bootstrap. The visual design is identical to the previous design, but it's now responsive. Making this change only took a few hours of effort, and saved me from trying to retrofit responsive utilities into my existing layout. It also gave me a chance to clean up my Django templates a bit.

At the same time, I changed the default template that my customers get to be much nicer than the black and white default I previously used. Pricing also got simplified; I took out both the cheap and expensive paid options and kept a single paid plan for $29. The pricing page is much simpler as a result.

API

For something a bit different, I installed and set up restless to get a REST API for some parts of the WhisperGifts site. For a while I've wanted to play around with some mobile client development, and a proper API will make that a bit easier. It's only just been announced and given the site's audience I am not expecting a huge amount of use, but it was an interesting project to undertake regardless.

This might also lead me to mess around with a single-page JavaScript app that can consume the API (specifically for the user dashboard side of things) but who knows when!

Weather lookups

If a WhisperGifts user has added the address of their wedding to their registry page, I use that address to do hyperlocal weather lookups using Forecast.io. I'm using python-forecastio, which makes the interesting part of this only a few lines of code:

forecast_result = forecastio.load_forecast(settings.FORECASTIO_API_KEY, lat, lng, time=registry.weddingdate)
weather = forecast_result.currently()
w_temp = weather.d.get('temperature', None)
w_summ = weather.d.get('summary', None)

if w_temp is not None and w_summ is not None:
    registry.weather = "%s, %s&deg;" % (w_summ, w_temp) # Results in "Partly cloudy, 19°".

I can then show this on the couple's registry page and use it in reminder emails sent to guests. At the moment I do these lookups daily for any registry that's within the next month; so far Forecast.io has weather details for 30 days out for most locations which is rather amazing.

None of these are specific to the wedding business, but it's been a fun way to play around with a few pieces of tech that haven't really fit into any other project so far.