"Казань": (55.770257, 55.830138, 49.088112, 49.181250),
"Самара": (53.171396, 53.299662, 50.066118, 50.288368),
"Санкт-Петербург": (59.896114, 59.993548, 30.231423, 30.413881),
- "Лондон": (51.464854, 51.575864,-0.181617, 0.012276)
+ "Лондон": (51.464854, 51.575864, -0.181617, 0.012276)
}
move_distance = 300
coordinate[1] + radius)
for o in near_objects['amenities']:
- game.tips.append(f'Рядом с вами находится {o["name"]}')
+ direction = get_direction(coordinate, (o['lat'], o['lon']))
+ game.tips.append(f'На {convert_direction(direction)}е от вас находится {o["name"]}')
for o in near_objects['rivers']:
game.tips.append(f'Рядом с вами протекает {o["name"]} 🌊')
success, summary = parse_summary(
s['name'].replace('улица', '').replace('проспект', '').replace('переулок', '').strip())
- if success and summary and 'улица' not in summary and not re.search(stemming(s['name']), stemming(summary), re.IGNORECASE):
- game.tips.append(f'{summary[0].capitalize() + summary[1:]}. Это как-то связано с названием ближайшей улицы 🤔')
+ if success and summary and 'улица' not in summary and not re.search(stemming(s['name']), stemming(summary),
+ re.IGNORECASE):
+ game.tips.append(
+ f'{summary[0].capitalize() + summary[1:]}. Это как-то связано с названием ближайшей улицы 🤔')
buildings = near_objects['buildings']
for s in near_objects['sightseeings']:
type = convert_sightseeing_type(s['type'])
+ direction = get_direction(coordinate, (s['lat'], s['lon']))
game.tips.append(
- f'Ð\9aÑ\81Ñ\82аÑ\82и, недалеко ' + (type if type else 'интересный туристический объект') + ': ' + s["name"])
+ f'Ð\9aÑ\81Ñ\82аÑ\82и, неподалекÑ\83 на {convert_direction(direction)}е еÑ\81Ñ\82Ñ\8c ' + (type if type else 'интересный туристический объект') + ': ' + s["name"])
shuffle(game.tips)
+def get_direction(my_coordinates, object_coordinates):
+ dlat = object_coordinates[0] - my_coordinates[0]
+ dlon = object_coordinates[1] - my_coordinates[1]
+
+ if abs(dlat) < abs(dlon):
+ return 'east' if dlon > 0 else 'west'
+
+ return 'north' if dlat > 0 else 'south'
+
+
def convert_building_type(building_type):
if building_type == 'dormitory':
return 'с общежитием'
add_tips(game)
- game.shown_tips.append(f'Вы переместились на {move_distance} м на {convert_direction(direction)}')
+ game.shown_tips.append(f'Вы переместились на {move_distance}м на {convert_direction(direction)}')
show_tips(game, 1)
Api = OsmApi()
pp = pprint.PrettyPrinter(indent=4)
-min_lon, min_lat, max_lon, max_lat = 30.3830262851,59.9141077326,30.4079171848,59.9222065257
+min_lon, min_lat, max_lon, max_lat = 30.3830262851, 59.9141077326, 30.4079171848, 59.9222065257
+
def remove_duplicates(l):
return [dict(t) for t in {tuple(d.items()) for d in l}]
+
def get_objects_from_square(min_lon, min_lat, max_lon, max_lat):
return Api.Map(min_lon, min_lat, max_lon, max_lat)
-
+
+
def filter_streets(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'highway' in o['data']['tag']
- and 'name' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'highway' in o['data']['tag']
+ and 'name' in o['data']['tag'], objects))
+
def filter_waterways(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'waterway' in o['data']['tag']
- and 'river' in o['data']['tag']['waterway']
- and 'name' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'waterway' in o['data']['tag']
+ and 'river' in o['data']['tag']['waterway']
+ and 'name' in o['data']['tag'], objects))
+
def filter_sightseeings(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and
- (('tourism' in o['data']['tag']
- and ('attraction' in o['data']['tag']['tourism']
- or 'artwork' in o['data']['tag']['tourism']
- or 'resort' in o['data']['tag']['tourism']
- or 'viewpoint' in o['data']['tag']['tourism']
- or 'museum' in o['data']['tag']['tourism']))
- or
- (('historic' in o['data']['tag']
- and ('memorial' in o['data']['tag']['historic']
- or 'monument' in o['data']['tag']['historic']
- or 'yes' in o['data']['tag']['historic']
- or 'building' in o['data']['tag']['historic']))))
- and 'name' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and
+ (('tourism' in o['data']['tag']
+ and ('attraction' in o['data']['tag']['tourism']
+ or 'artwork' in o['data']['tag']['tourism']
+ or 'resort' in o['data']['tag']['tourism']
+ or 'viewpoint' in o['data']['tag']['tourism']
+ or 'museum' in o['data']['tag']['tourism']))
+ or
+ (('historic' in o['data']['tag']
+ and ('memorial' in o['data']['tag']['historic']
+ or 'monument' in o['data']['tag']['historic']
+ or 'yes' in o['data']['tag']['historic']
+ or 'building' in o['data']['tag']['historic']))))
+ and 'name' in o['data']['tag'], objects))
+
def filter_buildings(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'building' in o['data']['tag']
- and 'building:levels' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'building' in o['data']['tag']
+ and 'building:levels' in o['data']['tag'], objects))
+
def filter_amenities(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'lat' in o['data']
- and 'lon' in o['data']
- and 'amenity' in o['data']['tag']
- and 'name' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'lat' in o['data']
+ and 'lon' in o['data']
+ and 'amenity' in o['data']['tag']
+ and 'name' in o['data']['tag'], objects))
+
def convert_building_type(building_type):
if building_type == 'dormitory':
else:
return 'building'
+
def filter_vehicles(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'vehicle' in o['data']['tag']
- and 'route' in o['data']['tag']
- and 'name' in o['data']['tag'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'vehicle' in o['data']['tag']
+ and 'route' in o['data']['tag']
+ and 'name' in o['data']['tag'], objects))
+
def convert_vehicle_type(vehicle_type):
if vehicle_type == 'bus':
if vehicle_type == 'train':
return 'train'
else:
- return 'unknown'
+ return 'unknown'
+
def filter_districts(objects):
- return list(filter(lambda o:
- o['data']['tag'] != {}
- and 'type' in o['data']['tag']
- and (o['data']['tag']['type'] == 'boundary' or 'boundary' in o['data']['tag'])
- and 'name' in o['data']['tag']
- and 'район' in o['data']['tag']['name'], objects))
+ return list(filter(lambda o:
+ o['data']['tag'] != {}
+ and 'type' in o['data']['tag']
+ and (o['data']['tag']['type'] == 'boundary' or 'boundary' in o['data']['tag'])
+ and 'name' in o['data']['tag']
+ and 'район' in o['data']['tag']['name'], objects))
+
def describe_objects(min_lat, min_lon, max_lat, max_lon):
objects = get_objects_from_square(min_lon, min_lat, max_lon, max_lat)
+
streets = [
- {'name': x['data']['tag']['name']} for x in filter_streets(objects)
+ {'name': x['data']['tag']['name']} for x in filter_streets(objects)
]
+
buildings = [
- {'building_type': convert_building_type(x['data']['tag']['building']),
- 'levels': x['data']['tag']['building:levels']} for x in filter_buildings(objects)
+ {'building_type': convert_building_type(x['data']['tag']['building']),
+ 'levels': x['data']['tag']['building:levels']} for x in filter_buildings(objects)
]
vehicles = [
- {'vehicle_type': convert_vehicle_type(x['data']['tag']['route']),
- 'name': re.split(r'\.', x['data']['tag']['name'].replace(':', '.'))[0]} for x in filter_vehicles(objects)
+ {'vehicle_type': convert_vehicle_type(x['data']['tag']['route']),
+ 'name': re.split(r'\.', x['data']['tag']['name'].replace(':', '.'))[0]} for x in filter_vehicles(objects)
]
sightseeings = [
- {'name': x['data']['tag']['name'], 'type': x['data']['tag']['tourism'] if 'tourism' in x['data']['tag'] else x['data']['tag']['historic']} for x in filter_sightseeings(objects)
+ {'name': x['data']['tag']['name'],
+ 'type': x['data']['tag']['tourism'] if 'tourism' in x['data']['tag'] else x['data']['tag']['historic'],
+ 'lat': x['data']['lat'],
+ 'lon': x['data']['lon']
+ } for x
+ in filter_sightseeings(objects)
]
districts = [
- {'name': x['data']['tag']['name']} for x in filter_districts(objects)
+ {'name': x['data']['tag']['name']} for x in filter_districts(objects)
]
rivers = [
- {'name': x['data']['tag']['name']} for x in filter_waterways(objects)
+ {'name': x['data']['tag']['name']} for x in filter_waterways(objects)
]
amenities = [
- {'name': x['data']['tag']['name'],
- 'type': x['data']['tag']['amenity'],
- 'lat': x['data']['lat'],
- 'lon': x['data']['lon']} for x in filter_amenities(objects)]
+ {'name': x['data']['tag']['name'],
+ 'type': x['data']['tag']['amenity'],
+ 'lat': x['data']['lat'],
+ 'lon': x['data']['lon']} for x in filter_amenities(objects)]
return {'center': {'lat': (min_lat + max_lat) / 2, 'lon': (min_lon + max_lon) / 2},
'streets': remove_duplicates(streets),
'vehicles': remove_duplicates(vehicles),
if __name__ == '__main__':
objects = describe_objects(min_lat, min_lon, max_lat, max_lon)
- pp.pprint(objects)
\ No newline at end of file
+ pp.pprint(objects)