def get_activity_count():
    try:
        f = SuperFeedrActivity.all()
        f.order("-activity_counter")
        activity = f[0]
        return int(activity.activity_counter)
    except:
        return 0
def receive_feeds(request):
    logging.info("receiving feed")
    if request.GET:
        logging.debug("#authenticating feed")
        challenge = request.GET.get("hub.challenge")
        return HttpResponse(challenge)
    if request.raw_post_data:
        logging.debug("#saving feed data")
        data = request.raw_post_data
        logging.debug(data)
        a = SuperFeedrActivity()
        a.update = data
        a.activity_counter = int(counter_helper.get_activity_count()) + 1
        a.save()
        logging.debug("#launching feed task")
        # do something with your feed update (this is will i queue a task to parse it)
        # taskqueue.Task(url=reverse("api-parse-feed-update"), params={'id': a.id}).add(queue_name='feedparsing')
        return HttpResponse("")
    logging.debug("Nope")
    return HttpResponse("hub.receive")
def view_superfeedr_updates(request):
    logging.info("view 10 most recent updates")
    query = SuperFeedrActivity.all()
    query.order("-created")
    activities_q = query.fetch(10)

    activities = []
    for activity in activities_q:
        activities.append(activity.update)

    activities_json = simplejson.dumps(activities)

    return HttpResponse(activities)