当前位置: 首页>>代码示例>>Python>>正文


Python exc.GeocoderTimedOut方法代码示例

本文整理汇总了Python中geopy.exc.GeocoderTimedOut方法的典型用法代码示例。如果您正苦于以下问题:Python exc.GeocoderTimedOut方法的具体用法?Python exc.GeocoderTimedOut怎么用?Python exc.GeocoderTimedOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geopy.exc的用法示例。


在下文中一共展示了exc.GeocoderTimedOut方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_geocoordinates

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def get_geocoordinates(geolocator, listing_object):
    address, city, state, zip_code = construct_full_address(listing_object)
    address_string_combinations = [
        '%s %s %s %s' % (address, city, state, zip_code),
        '%s %s %s' % (address, city, state),
        '%s %s' % (address, zip_code)
    ]
    location = None
    for address_string_combination in address_string_combinations:
        try:
            location = geolocator.geocode(address_string_combination)
        except (GeocoderTimedOut, GeocoderServiceError, GeocoderUnavailable):
            time.sleep(10)
            try:
                location = geolocator.geocode(address_string_combination)
            except (
                    GeocoderTimedOut, GeocoderServiceError,
                    GeocoderUnavailable):
                return None, None
        if location:
            return location.latitude, location.longitude
        else:
            continue
    if not location:
        return None, None 
开发者ID:bgirer,项目名称:rets-django,代码行数:27,代码来源:update_listings.py

示例2: retrying_set_location

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def retrying_set_location(location_name):
    """
    Continue trying to get co-ords from Google Location until we have them
    :param location_name: string to pass to Location API
    :return: None
    """

    while True:
        try:
            set_location(location_name)
            return
        except (GeocoderTimedOut, GeocoderServiceError), e:
            debug(
                'retrying_set_location: geocoder exception ({}), retrying'.format(
                    str(e)))
        time.sleep(1.25) 
开发者ID:rubenmak,项目名称:PokemonGo-SlackBot,代码行数:18,代码来源:pokehomey.py

示例3: geocode

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def geocode(self, address):
        if not isinstance(address, basestring) \
                and not isinstance(address, dict):
            err_msg = u"address should either be of type: %s, or of type %s." \
                      % (basestring, dict)
            raise TypeError(err_msg)

        try:
            geolocation = self._geocoder.geocode(address)

            if not geolocation:
                err_msg = u"Couldn't resolve the following address: '%s'" \
                          % address
                raise GeolocationFailure(err_msg)
        except (exc.GeocoderQuotaExceeded,
                exc.GeocoderUnavailable,
                exc.GeocoderTimedOut) as e:
            raise TemporaryError(u'Geolocator error: %s' % e)
        except exc.GeocoderServiceError as e:
            raise GeolocationError(u'Geolocator error: %s' % e)

        return geolocation 
开发者ID:pyjobs,项目名称:web,代码行数:24,代码来源:geolocation.py

示例4: get

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def get(self, request, *args, **kwargs):
        # Validate request
        form = CoordinatesFromAddressForm(request.GET)
        if not form.is_valid():
            return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
        address = form.cleaned_data['address']

        # Return lat/lon for address
        geolocator = Nominatim()
        try:
            location = geolocator.geocode(address)
        except GeocoderTimedOut:
            return Response(
                "Geocoder service currently unavailable. Please try again later.",
                status=status.HTTP_503_SERVICE_UNAVAILABLE
            )
        return Response({
            'latitude': float("{0:.4f}".format(location.latitude)),
            'longitude': float("{0:.4f}".format(location.longitude)),
        }) 
开发者ID:RevolutionTech,项目名称:perdiem-django,代码行数:22,代码来源:views.py

示例5: retrying_set_location

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def retrying_set_location(location_name):
    """
    Continue trying to get co-ords from Google Location until we have them
    :param location_name: string to pass to Location API
    :return: None
    """

    while True:
        try:
            set_location(location_name)
            return
        except (GeocoderTimedOut, GeocoderServiceError), e:
            debug(
                'retrying_set_location: geocoder exception ({}), retrying'.format(str(e)))
        time.sleep(1.25) 
开发者ID:Girish-Raguvir,项目名称:PokemonGo-RedStreak,代码行数:17,代码来源:main.py

示例6: dispatch

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def dispatch(self, request, *args, **kwargs):
        # Filtering
        self.active_genre = request.GET.get('genre', 'All Genres')
        self.distance = request.GET.get('distance')
        self.location = request.GET.get('location')
        self.lat = request.GET.get('lat')
        self.lon = request.GET.get('lon')

        # Sorting
        order_by_slug = request.GET.get('sort')
        if order_by_slug not in self.ORDER_BY_NAME:
            order_by_slug = 'recent'
        self.order_by = {
            'slug': order_by_slug,
            'name': self.ORDER_BY_NAME[order_by_slug],
        }

        # Geolocate if location
        self.location_coordinates = None
        self.geocoder_failed = False
        if self.location:
            geolocator = Nominatim()
            try:
                self.location_coordinates = geolocator.geocode(self.location)
            except GeocoderTimedOut:
                self.geocoder_failed = True

        return super(ArtistListView, self).dispatch(request, *args, **kwargs) 
开发者ID:RevolutionTech,项目名称:perdiem-django,代码行数:30,代码来源:views.py

示例7: geolocate

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderTimedOut [as 别名]
def geolocate(place):
    if place:
        print('geolocate', place)
        try:
            location = geolocator.geocode(place)
            if location:
                return {
                    'lat': location.latitude,
                    'lng': location.longitude,
                }
        except GeocoderTimedOut:
            print('geocoder timeout')
    return {} 
开发者ID:mdamien,项目名称:leboncoin-map,代码行数:15,代码来源:serv.py


注:本文中的geopy.exc.GeocoderTimedOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。