Example #1
0
def wiki_geosearch(option, opt_str, value, parser):
    length = len(parser.rargs)
    global geosearch_res
    if length < 2:
        parser.error(colored("option -g needs at least 2 arguments!", "red", attrs=["bold"]))
    elif length > 3:
        parser.error(colored("option -g can't handle more than 3 arguments!", "red", attrs=["bold"]))
    elif length == 2:
        [latitude, longtitude] = parser.rargs
        print '\n'+"=="*15+"result"+"=="*15+'\n'
        try:
            geosearch_res = wikipedia.geosearch(latitude, longtitude)
        except wikipedia.WikipediaException:
            parser.error(colored("An unknown error occured: 'Invalid coordinate provided'. Please report it on GitHub!",
                                 "red", attrs=["bold"]))
        for res in geosearch_res:
            cprint(res+'\n', "green")
        print '\n'+"=="*16+"end"+"=="*16+'\n'
    else:
        [latitude, longtitude, radius] = parser.rargs
        try:
            geosearch_res = wikipedia.geosearch(latitude, longtitude, radius=radius)
        except wikipedia.WikipediaException:
            parser.error(colored("An unknown error occured: 'Invalid coordinate provided'. Please report it on GitHub!",
                                 "red", attrs=["bold"]))
        print '\n'+"=="*15+"result"+"=="*15+'\n'
        for res in geosearch_res:
            cprint(res+'\n', "green")
        print '\n'+"=="*16+"end"+"=="*16+'\n'
Example #2
0
 def get_wiki_result(self):
     """
     Method to search a result in wikipedia
     if an answer exists then make an output of the 2 first sentences if they are existing
     otherwise send the "unfind" answer from the init
     """
     try:
         find_result = wikipedia.search(self.text_parsed)
         print(find_result)
         if not find_result:
             return self.unfind
         else:
             wik_page_name = find_result[0]
             description = wikipedia.summary(wik_page_name, sentences=2)
             resume = ("Alors alors! A ce que je comprends, "
                       "tu veux l'endroit à cette adresse: {}? "
                       "Non mais tu sais que {}."
                       .format(self.address, description))
             return resume
     except exceptions.DisambiguationError:
         use_coordinate = self.geocode
         description = wikipedia.geosearch(use_coordinate['lat'], use_coordinate['lng'])
         alternative_result = wikipedia.summary(description, sentences=2)
         alternative_answer = "{} Si ce n'est pas la réponse que tu attendais " \
                              "alors soit plus précis. Tu vois, si je te dis par exemple: 'Paris'. " \
                              "Ca veut dire quoi? La célébrité? la ville? le défi? " \
                              "Voyons mon petiot tu peux le faire!".format(alternative_result)
         return alternative_answer
     except wikipedia.exceptions.WikipediaException:
         use_coordinate = self.geocode
         description = wikipedia.geosearch(use_coordinate['lat'], use_coordinate['lng'])
         alternative_result = wikipedia.summary(description, sentences=2)
         alternative_answer = "{} C'est ça que tu voulais savoir??!!".format(alternative_result)
         return alternative_answer
Example #3
0
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    city_results = wikipedia.geosearch(latitude=lat,
                                       longitude=lon,
                                       title=None,
                                       results=10,
                                       radius=10000,
                                       feature_type='city')

    city_wiki = map(print_wiki, city_results)

    city_out = ""
    for i in city_wiki:
        city_out += str(i) + " "

    # event_results = wikipedia.geosearch(latitude=lat,
    #                                      longitude=lon,
    #                                      title=None,
    #                                      results=30,
    #                                      radius=10000,
    #                                      feature_type='event')
    #
    # if len(event_results) > 0:
    #     try:
    #         event_wiki = map(print_wiki, event_results)

    # else:
    #     event_wiki = None
    event_wiki = None

    return city_out
Example #4
0
    def geosearch(self, args):
        """::geosearch::
        used to find out what happend at a certain location or
        in the range of radius.
        examole:
        1. geosearch 180 27 -> return event take place at 180' 27'
        2. geosearch 180 27 100 -> return event take place in 100 meters range from
                point 180' 27'"""
        global geosearch_res
        [latitude, longtitude, radius] = [0] * 3

        if len(args) < 2 or len(args) > 3:
            raise AssertionError(colored("function geosearch handle 2 or 3 arguments!",\
                    "red", attrs=["bold"]))
        elif len(args) == 2:
            [latitude, longtitude] = args[:]
        elif len(args) == 3:
            [latitude, longtitude, radius] = args[:]

        try:
            geosearch_res = wikipedia.geosearch(latitude, longtitude, radius=radius)
        except wikipedia.WikipediaException:
            raise AssertionError(colored("An unknown error occured: 'Invalid coordinate\
                    provided'. Please report it on GitHub!", "red", attrs=["bold"]))

        for res in geosearch_res:
            cprint(res + '\n', "green")
Example #5
0
def wiki_geosearch(option, opt_str, value, parser):
    """
    used to find out what happend at a certain location or in the range of radius
    """
    length = len(parser.rargs)
    global geosearch_res
    [latitude, longtitude, radius] = [0] * 3

    if length < 2:
        parser.error(
            colored("option -g needs at least 2 arguments!",
                    "red",
                    attrs=["bold"]))
    elif length > 3:
        parser.error(
            colored("option -g can't handle more than 3 arguments!",
                    "red",
                    attrs=["bold"]))
    elif length == 2:
        [latitude, longtitude] = parser.rargs[:]
    else:
        [latitude, longtitude, radius] = parser.rargs[:]

    try:
        geosearch_res = geosearch(latitude, longtitude, radius=radius)
    except WikipediaException:
        parser.error(
            colored(
                "An unknown error occured: 'Invalid coordinate provided'. Please report it on GitHub!",
                "red",
                attrs=["bold"]))
        exit(1)
    for res in geosearch_res:
        cprint(res + '\n', "green")
Example #6
0
    def get_wiki_result(self, lat, lng, question):
        """Return the summary and the url of the wikipedia page searched"""
        try:
            wiki_page = wikipedia.page(question)

            return {"summary": wiki_page.summary[:500], "url": wiki_page.url}

        except (wikipedia.exceptions.PageError):
            return "no result"

        except (wikipedia.exceptions.DisambiguationError):
            try:
                wiki_search = wikipedia.geosearch(lat, lng, question)
                wiki_page = wikipedia.page(wiki_search[0])

                return {
                    "summary": wiki_page.summary[:500],
                    "url": wiki_page.url
                }

            except IndexError:
                return "no result"

            except (wikipedia.exceptions.DisambiguationError):
                return "no result"
Example #7
0
    def find_page_titles_around_point(
            self, point: Point, title=None, results=None,
            radius=10000) -> List[str]:
        """Find pages around point using Wikipedia Geosearch

        Args:
            - point: geographic point to search around
            - title: optional title of nearby page
            - results: max number of results. Not sure if None is unlimited
            - radius: search radius in meters. Between 10 and 10,000

        Returns:
            - Page _titles_ around point. Loading actual page metadata is
              slower, so that can be done in a later function, in case I want to
              get just titles to filter.
        """
        if not isinstance(point, Point):
            raise TypeError('point must be of type Point')
        if title is not None:
            if not isinstance(title, str):
                raise TypeError('title must be str')

        assert isinstance(point, Point), 'point must have Point geometry'
        lon, lat = list(point.coords)[0]

        res = wikipedia.geosearch(
            latitude=lat,
            longitude=lon,
            title=title,
            results=results,
            radius=radius)
        return res
def wiki_geosearch(option, opt_str, value, parser):
    """
    used to find out what happend at a certain location or in the range of radius
    """
    length = len(parser.rargs)
    global geosearch_res
    [latitude, longtitude, radius] = [0] * 3

    if length < 2:
        parser.error(colored("option -g needs at least 2 arguments!", "red", attrs=["bold"]))
    elif length > 3:
        parser.error(colored("option -g can't handle more than 3 arguments!", "red", attrs=["bold"]))
    elif length == 2:
        [latitude, longtitude] = parser.rargs[:]
    else:
        [latitude, longtitude, radius] = parser.rargs[:]

    try:
        geosearch_res = geosearch(latitude, longtitude, radius=radius)
    except WikipediaException:
        parser.error(
            colored(
                "An unknown error occured: 'Invalid coordinate provided'. Please report it on GitHub!",
                "red",
                attrs=["bold"],
            )
        )
        exit(1)
    for res in geosearch_res:
        cprint(res + "\n", "green")
Example #9
0
 def __get_page_title(self):
     """ find article from geocode"""
     wikipedia.set_lang("fr")
     self.page_title = wikipedia.geosearch(self.lat,
                                           self.long,
                                           title=None,
                                           results=1,
                                           radius=1000)[0]
    def get_geo_info(station):
        '''
        FIXME: some stations get None for district and neighborhood, maybe could be fixed by some algortithm that moves the point around until some non None result is obtained for both. See wikipedia also approach above

        TODO: the wikipedia approach could be improved by replacing exact matching by approximate matching, maybe with NLTK
        '''
        longitude, latitude = float(station['long']), float(station['lat'])
        # reverse geocoding
        # NOTE Geocoder.reverse_geocode returns a kind of iterator 
        # with objects that can only be consumed once, beware
        district, neighborhood, postalcode = None, None, None
        geo_results = None
        try: 
            geo_results = Geocoder.reverse_geocode(latitude, longitude)
        except:
            geo_results = None
        if geo_results != None:
            for result in geo_results:
                district = result.sublocality if (district == None) else district
                neighborhood = result.neighborhood if (neighborhood == None) else neighborhood
                if postalcode == None:
                    postalcode_match = _postalcode_re.match(str(result))
                    postalcode = postalcode_match.groupdict()['postalcode'] if (postalcode_match != None) else None
                if (filter(lambda x: x == None, [district, neighborhood, postalcode]) == []):
                    break

        # try with wikipedia if needed
        wikipedia_places = None
            # try by neighborhood
        if neighborhood == None:
            wikipedia_places = wikipedia.geosearch(latitude, longitude)
            for place in wikipedia_places:
                if place in _neighborhood_to_distric.keys():
                    neighborhood, district = place, _neighborhood_to_distric[place]
                    break
             # try by district
        if district == None:
            wikipedia_places = wikipedia_places if (wikipedia_places != None) else wikipedia.geosearch(longitude, latitude)
            for place in wikipedia_places:
                if place in _district_to_neighborhoods.keys():
                    district = place
                    break

        geo_info = {"district" : district, "neighborhood" : neighborhood, "postalcode" : postalcode}

        return geo_info
Example #11
0
def nearby(x):
    """Locates and returns any Wikipedia page whose physical location is near that of the page supplied."""
    try:
        (lat, lon) = x.coordinates
        return wikipedia.geosearch(lat, lon, radius=10000)
    except KeyError: # Accessing coordinates of a page that doesn't have them appears
                     # to throw a key error, despite documentation to the contrary.
        return None
Example #12
0
def wikigeo(lat, lon):
    l1 = wikipedia.geosearch(lat, lon, title=None, results=10, radius=1000)
    #print(l1[0])
    return (l1[0],
            wikipedia.summary(l1[0],
                              sentences=0,
                              chars=2048,
                              auto_suggest=False,
                              redirect=True))
Example #13
0
def process_geo(message):
    # noinspection PyBroadException
    try:
        lat, lan = (str(message.text).replace('E', '').replace('W', '').replace('N', '').replace('S', '').
                    replace('° ', '').replace('°', '').replace(',', '').replace('  ', ' ').split(" "))
        change_lang(message)
        for i in wikipedia.geosearch(latitude=lat, longitude=lan, results=5, radius=1000):
            bot.send_message(chat_id=message.chat.id, text=i, reply_markup=main_keyboard())
    except Exception:
        bot.send_message(chat_id=message.chat.id, text="Not a location.", reply_markup=main_keyboard())
Example #14
0
    def local_search(self):
        """
        Find nearby sites to self.location
        """

        # Search Wikipedia for nearby pages
        self.wiki_resp = wk.geosearch(self._coordinates[0],
                                      self._coordinates[1],
                                      results=self.results,
                                      radius=self.radius)
Example #15
0
def nearby(x):
    """
    Locates and returns any Wikipedia page whose physical location is near that of the page supplied.
    """
    try:
        (lat, lon) = x.coordinates
        return wikipedia.geosearch(lat, lon, radius=10000)
    except KeyError:  # Accessing coordinates of a page that doesn't have them appears
        # to throw a key error, despite documentation to the contrary.
        return None
Example #16
0
    def __set_lookup(self):
        # Makes a geosearch based on latitude
        # and longitude, gives back 5 possible
        # options in a str list

        self.__set_language()
        self.lookup = wikipedia.geosearch(self.data[1][0],
                                          self.data[1][1],
                                          results=5,
                                          radius=2000)
        return self.lookup
Example #17
0
def search(coord, place_name):
    """Finds the Wikipedia page corresponding to the given place.

    The current implementation requires Wikipedia geotags, meaning it'll miss:
    - Chains (Starbucks)
    - Corporate pages (Lagunitas, as opposed to the brewery site)
    - Area-based things (49-mile drive in SF)

    :param coord: is (latitude, longitude)
    :return: A wikipedia page title.
    """
    # We don't use the title arg of `wikipedia.geosearch`. It will return exact title matches, even if the geo location
    # does not match, so "Boulevard" will return a street rather than the restaurant (which is "Boulevard (restaurant)").
    wiki_page_titles = wikipedia.geosearch(*coord)
    return _match_place_name_to_wiki_page(place_name, wiki_page_titles)
Example #18
0
def run_alexa():
    command = take_commad()
    if "play" in command:
        song = command.replace("play", "")
        talk("playing..." + song)
        print(pywhatkit.playonyt(song))
    elif "time" in command:
        time = datetime.datetime.now().strftime("%I:%M %p")
        print(time)
        talk(f"current time is {time}")

    elif "who is" in command:
        person = command.replace("who is", "")
        info = wikipedia.summary(person, 1)
        print(info)
        talk(info)
    elif "location" in command:
        info = wikipedia.geosearch(48.109840, 11.476990)
        talk(info)

    elif "weather" in command:
        info = webbrowser.open(
            "https://www.google.com/search?q=weather+in+my+location&oq=weather+in+&aqs=chrome.1.69i57j0i67i457j0i20i263l2j0l2j69i60l2.5105j1j7&sourceid=chrome&ie=UTF-8"
        )
        info1 = command.replace("weather", "")
        print(info)
        talk(info1)

    elif "what about" in command:
        talk(
            "Sakhawat Hossain is a bangladeshi descent and now living in munich, germany"
        )

    elif "date" in command:
        talk("sorry I am not feeling well, I have a headache")

    elif "are you single" in command:
        talk("no, I am currently in a relationship with Aaminur")

    elif "joke" in command:
        talk(pyjokes.get_joke())
        print(pyjokes)

    else:
        print("please say it again ")
Example #19
0
 def wikiRef(self, key_lat, key_lon):
     wk.set_lang('en')
     try: 
         summ = wk.summary(self.key_city, sentences = 3)
         print('◈Wiki summary of '+self.key_city+'◈')
         print(summ+'..')
     except wk.exceptions.DisambiguationError:
         print('.')
         beatAmbig = wk.search(self.key_city)
         summ_1 = wk.summary(beatAmbig[1], sentences = 3)
         print('◈Wiki summary of '+self.key_city+'◈')
         print(summ_1+'..')
     except wk.exceptions.PageError:print('CANNOT FIND ANY DATA ON WIKI')
     finally:
         related = wk.geosearch(key_lat, key_lon, results = 5, radius = 10000)
         print('\n◈Geographically related results (up to 5 results)◈\n')
         num = 1
         for re in related:
             print(str(num)+'. '+re)
             num += 1
Example #20
0
def process_geo(message):
    try:
        lat, lan = (
            str(message.text)
            .replace("E", "")
            .replace("W", "")
            .replace("N", "")
            .replace("S", "")
            .replace("° ", "")
            .replace("°", "")
            .replace(",", "")
            .replace("  ", " ")
            .split(" ")
        )
        set_lang("en")
        locations = geosearch(latitude=lat, longitude=lan, results=10, radius=1000)
        if locations:
            nearby = "<b>Nearby locations</b> are..."
            bot.send_message(
                chat_id=message.chat.id,
                text=nearby,
                parse_mode="html",
                reply_markup=main_keyboard(),
            )
            for i in locations:
                bot.send_message(
                    chat_id=message.chat.id, text=i, reply_markup=main_keyboard()
                )
        else:
            sorry = "Sorry, can't find nearby locations"
            bot.send_message(
                chat_id=message.chat.id, text=sorry, reply_markup=main_keyboard()
            )
    except Exception:
        bot.send_message(
            chat_id=message.chat.id,
            text="Use <b>Map</b> to get coordinates.",
            parse_mode="html",
            reply_markup=main_keyboard(),
        )
Example #21
0
def wiki_geosearch(lat, lon, rad):
    loc_name = wikipedia.geosearch(lat, lon, radius=rad, results=30)    
    latLon = np.zeros(len(loc_name) * 2)
    summary = list()
    urls = list()
    x = 0
    y = 0
    while y < len(loc_name):
        page = wikipedia.page(str(loc_name[y]))
        sum_des = page.summary.encode('utf-8')
        summary.append(sum_des)
        url = page.url.encode('utf-8')
        urls.append(url)
        coord = page.coordinates        
        loc_name[y] = str(loc_name[y])          
        latLon[x] = float(coord[0])
        latLon[x+1] = float(coord[1])        
        x += 2
        y += 1
    latLon = latLon.reshape(len(loc_name), 2)
    latLon = latLon.tolist()
    return latLon, loc_name, summary, urls
Example #22
0
def index(request):
    """
    Twiiter and Wikipedia API Call
    """
    tweet_list = []
    wiki_list = []
    search = request.GET.get('search', '').strip()
    if search and request.method == 'GET':
        try:
            if request.GET.get('lag') and request.GET.get('log'):
                lag = request.GET.get('lag')
                log = request.GET.get('log')
                wiki_topic = wikipedia.geosearch(lag, log, search)
            else:
                wiki_topic = wikipedia.search(search, 15)
        except wikipedia.exceptions.DisambiguationError as e:
            print e.options
        for topic in wiki_topic:
            wiki = dict()
            wiki['topic'] = topic
            wiki_list.append(wiki)

        if request.GET.get('lag') and request.GET.get('log'):
            lag = request.GET.get('lag')
            log = request.GET.get('log')
            data = search_twitter(search, lag + ',' + log + ',100mi')
        else:
            data = search_twitter(search)

        results = data['statuses']

        for result in results:
            tweet = dict()
            tweet['user'] = result['user']['screen_name']
            tweet['tweet'] = result['text']
            tweet['img_url'] = result['user']['profile_image_url_https']
            tweet_list.append(tweet)

    return render(request, 'mexicoder/index.html', {'data': tweet_list, 'wikidata': wiki_list})
Example #23
0
    def get_history_url(self):
        wikipedia.set_lang("fr")

        try:
            place = wikipedia.geosearch(latitude=self.lat,
                                        longitude=self.lng,
                                        results=1)
            url = wikipedia.page(place[0]).url
            history = wikipedia.summary(place[0])
            return history, url
        # PageError if the page doesn’t exist
        except wikipedia.exceptions.PageError:
            return
        # DisambiguationError if the page is a disambiguation page
        except wikipedia.exceptions.DisambiguationError:
            return
        # WikipediaException if the latitude or longitude does not match any results
        except wikipedia.exceptions.WikipediaException:
            return
        # if wikipedia.geoserch gives an empty list(search for algeria) so wikipedia.page(place[0]).url raise an IndexError
        except IndexError:
            return
def wiki_geosearch(lat, lon, rad):
    loc_name = wikipedia.geosearch(lat, lon, radius=rad, results=30)
    latLon = np.zeros(len(loc_name) * 2)
    summary = list()
    urls = list()
    x = 0
    y = 0
    while y < len(loc_name):
        page = wikipedia.page(str(loc_name[y]))
        sum_des = page.summary.encode('utf-8')
        summary.append(sum_des)
        url = page.url.encode('utf-8')
        urls.append(url)
        coord = page.coordinates
        loc_name[y] = str(loc_name[y])
        latLon[x] = float(coord[0])
        latLon[x + 1] = float(coord[1])
        x += 2
        y += 1
    latLon = latLon.reshape(len(loc_name), 2)
    latLon = latLon.tolist()
    return latLon, loc_name, summary, urls
Example #25
0
def search_wiki_by_term(term, geo_search=False, lat="", lng=""):
    lang = 'en'
    count = 5
    radius = 10000
    wikipedia.set_lang(lang)

    items = []
    try:
        if geo_search:
            names = wikipedia.geosearch(float(lat), float(lng), title=term, results=count, radius=radius)
        else:
            names = wikipedia.search(term, results=count)
        for name in names:
            try:
                page = wikipedia.page(name)
                wiki = WikiItem(page.title, page.categories, page.summary, page.revision_id)
                items.append(wiki)
            except wikipedia.exceptions.DisambiguationError:
                continue
        return items
    except wikipedia.exceptions.WikipediaException:
        raise WikiAPIQueryError
Example #26
0
def get_wikipedia_data_near_coords(latitude, longitude):
    """Get 10 data max near (10km) gps coords

    ex :GmapLatitude":"47.9908779", "GmapLongitude":"0.24142796"

    :param arg1: latitude
    :param arg2: longitude
    :type arg1: <float>
    :type arg2: <float>

    """

    # Get titles of pages
    #wikipedia.geosearch(latitude, longitude, results=10, radius=10000)
    #    Keyword arguments:
    #
    #        title - The title of an article to search for
    #        results - the maximum number of results returned
    #        radius - Search radius in meters. The value must be between 10 and 10000
    article_titles = wikipedia.geosearch(float(latitude), float(longitude))

    return [get_wikipedia_article_info(article_title) for article_title 
                in article_titles]
import wikipedia
wikipedia.set_lang("zh-tw")
import wikitextparser as wtp
from hanziconv import HanziConv

# 台灣歷史年表
# 台灣歷史
# 台灣日治時期
# 臺灣古蹟列表
# TODO: 若整個頁面有一個地點,所有裡面的歷史事件就用該頁面的地點
# TODO: 若整個頁面非一個地點,所有歷史事件就用該句子中有包含的地點。若該歷史事件的句子還是沒有
page = wikipedia.page('臺灣古蹟列表')

from get_place import *
for site in page.links[0:10]:
    print(site)
    print(get_places(site))
wikipedia.page('三崁店社')
中華民國直轄市定古蹟

wikipedia.search('古蹟')

wikipedia.page('中正紀念堂').coordinates
wikipedia.geosearch(25.03555555999999882033080211840569972991943359375,121.51972222000000556363374926149845123291015625)
Example #28
0
    def find_page_by_name(self, name: str, point=None, radius=None):
        """Find a single Wikipedia page given a name

        Search for the top 5 results. If there's a result with the exact same
        normalized name, choose that article. Otherwise, choose the first
        result.

        Note that even when the name is not exactly the same, the first result
        usually makes sense. For example, the first result for "Mount Rainier
        Wilderness" is "Mount Rainier National Park". And it would be ok to show
        the wikipedia page for the National Park when a user clicks on the
        wilderness polygon.

        Args:
            - name: name to search for
            - point: point in WGS84 to search around
            - radius: radius in meters to search around point
        """
        if not isinstance(name, str):
            raise TypeError('name must be str')
        if point is not None:
            if not isinstance(point, Point):
                raise TypeError('point must be of type Point')
        if radius is not None and radius > 10000:
            raise ValueError('max radius 10,000 meters')

        if point is None:
            res = wikipedia.search(name, results=5)
        else:
            lon, lat = list(point.coords)[0]
            radius = 400 if radius is None else radius
            res = wikipedia.geosearch(
                latitude=lat,
                longitude=lon,
                title=name,
                results=5,
                radius=radius)

        exact_match = [
            ind for ind, s in enumerate(res)
            if normalize_string(s) == normalize_string(name)
        ]
        choice = None
        if exact_match != []:
            choice = exact_match[0]
        else:
            choice = 0

        # Here turn auto_suggest to False because I know the page name exists
        # Otherwise sometimes the page names redirect from a name that exists to
        # a name that does not. For example, searching
        # ```
        # wikipedia.page('Shasta-Trinity National Forest')
        # ```
        # raises `PageError: Page id "shasta trinity national forests" does not
        # match any pages. Try another id!`, while the page does exist:
        # https://en.wikipedia.org/wiki/Shasta%E2%80%93Trinity_National_Forest
        # See also
        # https://github.com/goldsmith/Wikipedia/issues/192
        # https://github.com/goldsmith/Wikipedia/issues/176
        return wikipedia.page(res[choice], auto_suggest=False)
 def geosearch(self, lat, longitude, num_results=1, radius=1000):
     return wikipedia.geosearch(lat, longitude, results=num_results, radius=radius)
    def get_info_handler(self, bus_message):
        '''
        {'topic'   : <keyword>,
         'summary' : <numSentences>,
         'geosearch' : {'lat'    : <float>,
                        'long'   : <float>
                        'radius' : <int>
                        },
         'coordinates' : 'True',
         'references'  : 'True'
         }
         
        :param bus_message:
        :type bus_message:
        '''
        #print(bus_message.content)
        try:
            req_dict = json.loads(bus_message.content)
        except ValueError:
            err_resp = {'error' : 'Bad json in wikipedia request: %s' % str(bus_message.content)}
            resp = self.bus.makeResponseMsg(bus_message, 
                                            json.dumps(err_resp))
            self.bus.publish(resp)
            return
        
        try:
            self.check_req_correctness(req_dict)
        except ValueError as e:
            err_resp = {'error' : '%s' % `e`}
            resp = self.bus.makeResponseMsg(bus_message, json.dumps(err_resp))
            self.bus.publish(resp)
            
        res_dict = {}
        
        if req_dict.get('summary', None) is not None:
            summary = wikipedia.summary(req_dict['topic'], 
                                        sentences=req_dict['summary'])
            res_dict['summary'] = summary.encode('UTF-8', 'replace')
            wants_page = False
        else:
            # Wants whole page content:
            wants_page = True
            
        if req_dict.get('geosearch', None) is not None:
            geo_parms = req_dict['geosearch'] 
            lat = geo_parms['lat']
            longitude = geo_parms['long']
            radius = geo_parms['radius']
            
            res_dict['geosearch'] = wikipedia.geosearch(lat, longitude, req_dict['topic'], radius)
        
        # Remaining request possibilities require the page to be obtained,
        # even if summary was requested:
        page = None
        
        if req_dict.get(u'coordinates', None) is not None and req_dict['coordinates']:
            if page is None:
                page = wikipedia.page(req_dict['topic'])
            try:
                (lat, longitude) = page.coordinates
                res_dict['coordinates'] = '{"lat" : "%s", "long" : "%s"}' %\
                                            (str(lat), str(longitude))
            except KeyError:
                # Wikipedia entry has not coordinates associated with it:
                res_dict['coordinates'] = '"None"'
            
        if req_dict.get('references', None) is not None and req_dict['references']:
            if page is None:
                page = wikipedia.page(req_dict['topic'])
            res_dict['references'] = page.coordinates

        if wants_page:
            if page is None:
                page = wikipedia.page(req_dict['topic'])
            res_dict['content'] = page.content
            
        resp_msg = self.bus.makeResponseMsg(bus_message, json.dumps(res_dict))
        self.bus.publish(resp_msg)
Example #31
0
"""Code snippets vol-53
   261-Wikipedia geo search.

   Download all snippets so far:
   https://wp.me/Pa5TU8-1yg

   Blog: stevepython.wordpress.com

Requirements:
pip3 install wikipedia
https://pypi.org/project/wikipedia/

Origin: Unknown (sorry, had this on my drive for ages with no origin.)
"""
import wikipedia

print(wikipedia.geosearch(51.505905, -0.022066))

#returns:
#['Cabot Square', 'West India Quay', 'Canary Wharf',
#'International Sugar Organization', 'SS Robin',
#'Canary Wharf DLR station', '1 Cabot Square',
#'1 West India Quay', '25 North Colonnade', 'Marriott Canary Wharf']
Example #32
0
def locate(lat, lon):
    speak(
        "Based on Wikipedia geosearch here we have the most important places near that coordinates"
    )
    print(wikipedia.geosearch(lat, lon))
Example #33
0
ny = wikipedia.page("pondicherry")
print ny.title
print ny.url
#print ny.content.encode("iso-8859-15", "xmlcharrefreplace")
#print ny.links[0]
#print wikipedia.summary("Facebook")

'''

wikipedia.search(query, results=10, suggestion=False)
Do a Wikipedia search for query.

Keyword arguments:

results - the maxmimum number of results returned
suggestion - if True, return results and suggestion (if any) in a tuple
'''
queries = wikipedia.search('Facebook',results = 51, suggestion = True)
#print query
print queries
#print len(queries)
for query in queries:
    print query
print wikipedia.suggest('Facebook')
print wikipedia.summary('Facebook', sentences=2, chars=10, auto_suggest=True, redirect=True)
print wikipedia.page(title="Facebook", pageid=None, auto_suggest=True, redirect=True, preload=False)

print wikipedia.geosearch(72.0, 12.0 , title='Facebook', results=10, radius=1000)

wikipage = wikipedia.WikipediaPage(title='Facebook', pageid=None, redirect=True, preload=False, original_title=u'')
print wikipage
Example #34
0
 def location_search(self):
     geo_location = wikipedia.geosearch(37.787, -122.4)
Example #35
0
import pandas as pd

##Query 1: finding out more about Hamilton, this returns a list of search results.
## There are three possible arguments, the first is the search parameter, the second
## is a limit on the number of results that can show on a page, and the last is a boolean to 
## turn on and off auto-suggestions
search_param = "Hamilton"
num_results = 100
print(wikipedia.search(search_param, results = num_results, suggestion = True))

## Query 2: finding wikipedia articles related to longitude and latitude 
## coordinates. These coordinates for example are from a california earthquake
## returns a list of results markes as within 10,000 m, which is also the upper bound of the radius parameter
latitude = 35.3400
longitude = -120.1900
print(wikipedia.geosearch(latitude, longitude, radius = 10000))


#Query 3: Opening up a wikipedia page, and then you can access features in the WikipediaPage
## object like the content (a full printout of the entire page) or images, a list of all the image urls in that page
Columbia_University = wikipedia.WikipediaPage("Columbia University")
print(Columbia_University.content)
print(Columbia_University.images)

##with these queries, you can build cool datasets like the following, where you can get a csv of wikipedia articles that happen around earthquake coordinates:

latitude_list = [37.86319, 51.272222222222, 3.244, 18.513815, -40.8158]
longitude_list = [-122.25365, 30.224166666667, 95.825, -72.288193, -72.0028]
radius_list = []
for i in range(0, len(latitude_list)):
	radius_list.append(wikipedia.geosearch(latitude_list[i], longitude_list[i], results = 500, radius = 10000))
Example #36
0
                                      lat=centerLat,
                                      lon=centerLon,
                                      radius=10,
                                      in_gallery=True)
        for photo in photos['photos']['photo']:
            photoDict.append(photo)
    except:
        continue

pois = {}
rawTexts = {}
poiTitleToId = {}
myId = 1

#GET ALL POIS
wikiRes = wikipedia.geosearch(centerLat, centerLon, results=1000, radius=10000)
for ind, title in enumerate(wikiRes):
    print(ind)
    try:
        page = wikipedia.page(title)
        plat, plon = map(float, page.coordinates)
        poiTitleToId[title] = myId
        pois[myId] = {'name': title, 'lat': plat, 'lon': plon}
        rawTexts[myId] = page.content
        myId += 1
    except:
        continue

with open('dictionary.txt', 'w') as f:
    for title in poiTitleToId:
        f.write(title + '\t' + str(poiTitleToId[title]) + '\t' +
wp.search('Ireland', results=5)

# Get the summary
wp.summary('Ireland')
wp.summary('Ireland', sentences=1)

# Get a full page
Dublin = wp.page('Dublin')
Dublin.title
Dublin.url
Dublin.content
Dublin.images
Dublin.links

# Geosearch searches by latitude
wp.geosearch(48.8582, 2.2945, radius=100)

# Get a random page
wp.random(pages=1)

# Get the raw html
Dublin_raw = wp.WikipediaPage('Dublin')
Dublin_raw.html()  # Slow
# Can get way more rich stuff with this too, including revision IDs and similar

# Some fun ideas
# Find two random pages and see if you can link them together via intermediate pages using the links object
# Create a social network matrix of articles that link to each other
# Use regular expressions to extract interesting bits of text from pages. e.g. what's the most popular word used on wikipedia?
# Any other good ideas?
 def search_by_geocoordinates(geo_lat, geo_lon, poi_name = None):
     results = wikipedia.geosearch(geo_lat, geo_lon, poi_name)
     return results
Example #39
0
 def search_info(self):
     '''
     Returns the list of infomation about the city
     '''
     self.info = wikipedia.geosearch(self.crd[0], self.crd[1])
     return self.info
Example #40
0
 def wikiGeo(self):  #주변 장소
     related = wk.geosearch(self.lat, self.lon, results=5, radius=7000)
     return related
Example #41
0
def get_geo_articles(location_page_link, limit=100):
    article = wikipedia.page(location_page_link)
    coords = article.coordinates
    lat, lon = coords
    neighbors = wikipedia.geosearch(lat, lon, results=limit, radius=10000)
    return neighbors
Example #42
0
import wikipedia
print(wikipedia.search("Bill"))
print(wikipedia.suggest("Bill cliton"))
#print(wikipedia.summary("Ubuntu"))
# print(wikipedia.summary("key"))
# print(wikipedia.summary("Key (cryptography)"))
print(wikipedia.page("Ubuntu"))
print(wikipedia.page("Python").content)
print(wikipedia.page("Python").url)
print(wikipedia.page("Python").references)
print(wikipedia.page("Python").title)
print(wikipedia.page("Python").categories)
print(wikipedia.page("Ubuntu").links)
print(wikipedia.geosearch(37.787, -122.4))
print(wikipedia.page(37.787, -122.4))
wikipedia.set_lang("de")
print(wikipedia.summary("ubuntu", sentences=2))

print(wikipedia.languages())
print(wikipedia.page("ubuntu").images[0])
print(wikipedia.page("Ubuntu").html())