示例#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_isolate_name(self):
     """Tests for `isolate_name` function."""
     # Right now, tests are only for spanish names
     names = ['Calle de la PyConES',
              'Avenida del Rey Kiko I',
              'Paseo de los Torpedos',
              'Vía de las PyLadies',
              'Calle de Python']
     expected = ['pycones', 'rey kiko i', 'torpedos', 
                 'pyladies', 'python']
     for n, e in zip(names, expected):
         result = isolate_name(n)
         expected = e
         self.assertEqual(result, expected)