Esempio n. 1
0
    def get_request(self, place):
        """Return Gmaps request JSON object"""
        params = {
            "query": place,
            "key": google_map_key
        }

        return json_request(self.url, params)
def test_request():
    """Test known request to wikipedia API"""

    json_req = request.json_request(
        "https://fr.wikipedia.org/w/api.php", {
            "action": "query",
            "format": "json",
            "list": "search",
            "srsearch": "kjbfiurgifr",
            "srlimit": "1"
        })

    assert 'query' in json_req
Esempio n. 3
0
    def search_pages(self, search):
        """Search information get by Google Maps API in title of wiki page"""

        params = {
            "action": "query",
            "format": "json",
            "list": "search",
            "srsearch": search,
            "srlimit": "1"
        }
        data = json_request(self.url, params)
        result = data['query']['search']

        if len(result) > 0:
            title = result[0]['title']
        else:
            raise ValueError("Aucun résultat")

        return title
Esempio n. 4
0
    def get_url(self, title):
        """"
        Search page with Wikipedia title page
        Get full URL of this page.
        """

        params = {
            "action": "query",
            "prop": "info",
            "titles": title,
            "inprop": "url",
            "formatversion": "2",
            "format": "json"
        }

        data = json_request(self.url, params)
        result = data['query']['pages']

        url = result[0]['fullurl']

        return url
Esempio n. 5
0
    def get_desc(self, title):
        """"
        Search page with Wikipedia title page
        Extract of tiny description (3 sentences).
        """

        params = {
            "action": "query",
            "prop": "extracts",
            "exsentences": "3",
            "exlimit": "1",
            "titles": title,
            "explaintext": "1",
            "formatversion": "2",
            "format": "json"
        }

        data = json_request(self.url, params)
        result = data['query']['pages']

        description = result[0]['extract'].split('==')[0]

        return description