示例#1
0
def wiki():
    if request.method == 'POST':
        address = get_address(
            request.form['inputlon'],
            request.form['inputlat']
        )
        if 'road' in address['address'].keys():
            title = isolate_name(address['address']['road'])
            article = get_wiki_info(title)
            if isinstance(article, str):
                result = article
            else:
                result = parse_wiki_content(article)
            return render_template("wiki.html", 
                                   result = result,
                                   address = address)
        elif 'pedestrian' in address['address'].keys():
            title = isolate_name(address['address']['pedestrian'])
            article = get_wiki_info(title)
            if isinstance(article, str):
                result = article
            else:
                result = parse_wiki_content(article)
            return render_template("wiki.html", 
                                   result = result,
                                   address = dict(address))
        elif address['NoDataError']:
            return render_template("wiki.html",
                                   result = "<h2>:-(</h2>",
                                   address = dict(address))
        elif address['UrlError']:
            return render_template("wiki.html",
                                   result = ("<h2>Parece que no "
                                             "podemos conectar a "
                                             "alguno de los servicios "
                                             "que usa la aplicación."
                                             "</h2>"),
                                   address = address)
        else:
            return render_template("wiki.html",
                                   result = ("<h2>No sabemos qué ha "
                                             "pasado. Lo sentimos en "
                                             "más profundo de nuestro "
                                             "frágil corazón</h2>"),
                                   address = address)
示例#2
0
 def test_parse_wiki_content(self):
     """Tests for the `get_wiki_info` function."""
     result = get_wiki_info('Python')
     parsed = parse_wiki_content(result)
     self.assertTrue(isinstance(parsed, str))
     self.assertEqual(parsed[:6], '<H1><A')