Posts Tagged ‘google app engine’

My First Callcast

Wednesday, June 4th, 2008

Check it out.  Thanks Kevin!

friendfeed.py Patch for use on Google App Engine

Thursday, May 29th, 2008

Ask and ye shall receive.  Attached is a patch for using friendfeed.py on Google App Engine.  You need to also have demjson available.  Google App Engine does not allow use of many C modules (like cjson) and both json and simplejson will throw decoding errors from time to time. demjson is slow but won’t throw errors around (I really wish we could use cjson; it’s so much faster).

Basically the differences are:

  1. Use urlfetch instead of urllib2
  2. Use Django’s urlencode which will work with unicode (letting you comment/share in languages like Chinese)
  3. Use demjson instead of cjson (which cannot be used on Google App Engine), simplejson, or json (which both throw decoding errors from time to time)

Enjoy!

Update:

You don’t need to use demjson anymore; simplejson will work just fine.  I just got an email from Sanjeev saying that they fixed the issue (’\x’ is not valid JSON).  This makes things even easier because simplejson is included in Django (from django.utils import simplejson) which is included in Google App Engine.

Google App Engine + Memcached + FF To Go = Bliss

Wednesday, May 28th, 2008

Google App Engine gained support for memcached today, a very high performance caching system, and I’m already using it in FF To Go.

I’ll share some code with you so you know how it works.  This is the code that renders the public feed:

def public(request):
    f = friendfeed.FriendFeed()
    try:
        start = int(request.GET.get('start', 0))
    except:
        start = 0
    service = request.GET.get('service', None)
    num = int(request.session.get('num', NUM))
    key = 'public_%i_%i_%s' % (num, start, service)
    data = memcache.get(key)
    if not data:
        try:
            data = f.fetch_public_feed(num=num, start=start, service=service)
        except Exception, e:
            return HttpResponseRedirect('/%s/' % e)
        memcache.set(key, data, CACHE_TIME)
    extra_context = {
        'entries': data['entries'],
        'next': start + num,
    }
    if start > 0:
        extra_context['has_previous'] = True
        extra_context['previous'] = start - num
    return render_to_response('public.html', extra_context, context_instance=RequestContext(request))

And that’s it!  The FriendFeed team should be happy; I’m using less of their resources because I don’t need to query them as much as I used to.  Now this is really only useful on the FriendFeed public feed because all other feeds are likely to be accessed using your FriendFeed credentials and have user specific differences (ie hiding settings) which we don’t want to cache but the public feed does not respond to your hide settings so it is a good candidate.  It’s nice to see that using memcached on Google App Engine is no different from using it on your own server.

Am I the first to use memcached on Google App Engine?