utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:goose-search 作者: rezemika 项目源码 文件源码
def __init__(self, uuid, geojson, search_preset, user_coordinates, timezone_name):
        self.uuid = uuid
        if geojson['geometry']['type'] == "Point":
            self.osm_meta = ("node", geojson["id"])
            self.coordinates = (
                geojson["geometry"]["coordinates"][1],
                geojson["geometry"]["coordinates"][0]
            )
        else:  # Should be "LineString".
            self.osm_meta = ("way", geojson["id"])
            self.coordinates = (
                geojson["geometry"]["coordinates"][0][1],
                geojson["geometry"]["coordinates"][0][0]
            )
        self.user_coords = user_coordinates
        self.search_preset = search_preset
        self.properties = geojson["properties"]
        self.default_address = self.get_default_address()
        self.string_address = ''
        self.distance = round(distance.vincenty(
            (user_coordinates[0], user_coordinates[1]), self.coordinates
        ).m)
        self.bearing = get_bearing(user_coordinates, self.coordinates)
        self.direction = deg2dir(self.bearing)
        oh_field = self.properties.get("opening_hours")
        self.opening_hours = None
        lang = get_language().split('-')[0]
        if lang not in ["fr", "en"]:
            lang = "en"
        if oh_field:
            try:
                self.opening_hours = humanized_opening_hours.HumanizedOpeningHours(
                    oh_field, lang, tz=pytz.timezone(timezone_name)
                )
            except humanized_opening_hours.HOHError:
                # TODO : Warn user ?
                debug_logger.error(
                    "Opening hours - HOHError ; OSM_ID: '{id}' ; opening_hours: '{oh}'".format(
                        id=self.osm_meta[1],
                        oh=oh_field
                    )
                )
                self.opening_hours = None
            except Exception as e:
                # TODO : Warn user ?
                debug_logger.error(
                    "Opening hours - Error ; Exception: '{exception}' ; OSM_ID: '{id}' ; opening_hours: '{oh}'".format(
                        exception=str(e),
                        id=self.osm_meta[1],
                        oh=oh_field
                    )
                )
                self.opening_hours = None
        self.tags = self.get_tags()
        self.renderable_tags = [t[0] for t in self.tags]
        return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号