<commit_before>#!/usr/bin/python
#
# Copyright 2011 Friday Film Club. All Rights Reserved.

"""Main views of the Friday Film Club app."""

__author__ = '<EMAIL> (<NAME>)'

import logging
import os
import re

import webapp2
from google.appengine.api import memcache, urlfetch
from google.appengine.ext import ndb

import baserequesthandler
import models



class SuggestHandler(baserequesthandler.RequestHandler):
  """Returns JSON suggesting film titles given a starting string."""

  def get(self, prefix):
    """foo"""
    prefix = prefix and prefix.strip()

    if not prefix:
      return webapp2.Response('')

    self.set_json_content_type()

    url = 'http://films-data.appspot.com/api?q=' + prefix
    content = urlfetch.fetch(url=url, follow_redirects=False).content
    return self.response.out.write(content)

    # memcached = memcache.get(prefix + callback)
    # if memcached and self.is_debug_mode():
    #   return webapp2.Response(memcached)
    #
    # film_index = models.FilmIndex.get_by_id(prefix)
    #
    # if film_index:
    #   films = ndb.get_multi(film_index.films)
    #   return self.render_json([f.to_dict() for f in films])
    # else:
    #   return self.render_empty()<commit_msg>Add memcached to films suggest. See #19<commit_after>#!/usr/bin/python
#
# Copyright 2011 Friday Film Club. All Rights Reserved.

"""Main views of the Friday Film Club app."""

__author__ = '<EMAIL> (<NAME>)'

import logging
import os
import re

import webapp2
from google.appengine.api import memcache, urlfetch
from google.appengine.ext import ndb

import baserequesthandler
import models



class SuggestHandler(baserequesthandler.RequestHandler):
  """Returns JSON suggesting film titles given a starting string."""

  def get(self, prefix):
    """Use the films data api to get film suggestions."""
    prefix = prefix and prefix.strip()

    if not prefix:
      return webapp2.Response('')

    self.set_json_content_type()

    memcached = memcache.get(prefix)
    if memcached and not self.is_debug_mode():
      return webapp2.Response(memcached)

    url = 'http://films-data.appspot.com/api?q=' + prefix
    content = urlfetch.fetch(url=url, follow_redirects=False).content
    return self.response.out.write(content)
{'fraction_non_alphanumeric': 0.10957683741648107, 'fraction_numerical': 0.0071269487750556795, 'mean_word_length': 3.893246187363834, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6223437', 'n_tokens_mistral': 715, 'n_tokens_neox': 671, 'n_words': 194}