def search_view(request): if request.method == 'GET' and 'q' in request.GET: return { 'query': request.GET['q'], 'countries': dict((v, k) for k, v in cctlds.iteritems()), 'result': zeitgeist_borders.google_instants(request.GET['q']) } else: return {}
def search_view(request): if request.method == 'GET' and 'q' in request.GET: return {'query': request.GET['q'], 'countries': dict((v, k) for k, v in cctlds.iteritems()), 'result': zeitgeist_borders.google_instants(request.GET['q'])} else: return {}
def google_instants(query): q = Queue() result = {} for country, tld in cctlds.iteritems(): Thread(target=google_instant, args=(q, country, tld, query)).start() waiting = len(cctlds) while waiting > 0: country, suggestions = q.get() result[country] = suggestions waiting -= 1 return result