Spaces:
Sleeping
Sleeping
Download location.py from ArielKes/RoutePlannerApp: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/spaces/ArielKes/RoutePlannerApp/resolve/main/location.py
- Command line
-
hf download hf://spaces/ArielKes/RoutePlannerApp/location.py
-
curl -L -o location.py https://huggingface.co/spaces/ArielKes/RoutePlannerApp/resolve/main/location.py
2.29 kB
| import re | |
| class Location: | |
| def __init__(self, address): | |
| self.address = address | |
| self.city = None | |
| self.street = None | |
| self.building = None | |
| self.coords = None | |
| self.coords_level = 'city' | |
| self.city_bbox = None | |
| self.parse_address() | |
| def __str__(self): | |
| if self.coords: | |
| return f""" | |
| --------------------------------------- | |
| city: {self.city} | |
| street: {self.street} | |
| building: {self.building} | |
| coords: {self.coords} | |
| coords level: {self.coords_level} | |
| """ | |
| else: | |
| return f""" | |
| --------------------------------------- | |
| city: {self.city} | |
| street: {self.street} | |
| building: {self.building} | |
| """ | |
| def to_dict(self): | |
| return { | |
| "Address": self.address, | |
| "City": self.city, | |
| "Street": self.street, | |
| "Building": self.building, | |
| "Coordinates": f"{self.coords[0]}, {self.coords[1]}" if self.coords else None, | |
| "Precision": self.coords_level, | |
| } | |
| def set_coords_level(self, level): | |
| self.coords_level = level | |
| def set_coords(self, lat, lon): | |
| self.coords = (lat, lon) | |
| def set_city_bbox(self, tl_lat, tl_lon, br_lat, br_lon): | |
| self.city_bbox = (tl_lat, tl_lon, br_lat, br_lon) | |
| def parse_address(self): | |
| """ | |
| Parses address of the form: "StreetName BuildingNumber, CityName" | |
| Example: "讙讜砖谉 1 ,拽专讬转 诪讜爪拽讬谉" | |
| """ | |
| if not self.address or ',' not in self.address: | |
| return | |
| try: | |
| before_comma, after_comma = self.address.split(',', 1) | |
| self.city = after_comma.strip() | |
| # Regex: match "专讞讜讘 [砖诐] 诪住驻专 [诪住驻专]" or just "[砖诐] [诪住驻专]" | |
| match = re.match(r'(.+?)\s+(\d+)', before_comma.strip()) | |
| if match: | |
| self.street = match.group(1).strip() | |
| self.building = match.group(2).strip() | |
| except Exception as e: | |
| print(f"Failed to parse address: {self.address}. Error: {e}") |