Exemplo n.º 1
0
def query(request):
    try:
        word = request.GET.get("query")  # get the query phrase
        box = request.GET.get("location")

        if word is not None:  # if a query exists

            if box:
                twitter_results = search_twitter_by_location(request, word)
            else:
                twitter_results = search_twitter(word)  # search Twitter and

            wiki_results = search_wikipedia(word)  # search Wikipedia

            context = {"word": word, "twitter_results": twitter_results, "wiki_results": wiki_results}
        else:  # if a query does not exist
            context = {}  # there is no context
    except:
        context = {}

    return render(request, "app/search.html", context)
Exemplo n.º 2
0
 def test_wikipedia_raises_disambiguation_error(self):
     """Tests disambiguation error is thrown"""
     self.assertRaises(wikipedia.DisambiguationError, wiki_results=search_wikipedia('banana'))
Exemplo n.º 3
0
 def test_wikipedia_results_is_none(self):
     """Tests no results are returned from Wikipedia"""
     wiki_results = search_wikipedia('kristinottofy');
     self.assertEquals(wiki_results, [])