mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-11 21:34:06 +00:00
use NominatimAPI in with context in CLI tool
This commit is contained in:
@@ -180,7 +180,7 @@ class APISearch:
|
|||||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||||
'Use --list-formats to see supported formats.')
|
'Use --list-formats to see supported formats.')
|
||||||
|
|
||||||
api = napi.NominatimAPI(args.project_dir)
|
with napi.NominatimAPI(args.project_dir) as api:
|
||||||
params: Dict[str, Any] = {'max_results': args.limit + min(args.limit, 10),
|
params: Dict[str, Any] = {'max_results': args.limit + min(args.limit, 10),
|
||||||
'address_details': True, # needed for display name
|
'address_details': True, # needed for display name
|
||||||
'geometry_output': _get_geometry_output(args),
|
'geometry_output': _get_geometry_output(args),
|
||||||
@@ -260,10 +260,11 @@ class APIReverse:
|
|||||||
if args.lat is None or args.lon is None:
|
if args.lat is None or args.lon is None:
|
||||||
raise UsageError("lat' and 'lon' parameters are required.")
|
raise UsageError("lat' and 'lon' parameters are required.")
|
||||||
|
|
||||||
api = napi.NominatimAPI(args.project_dir)
|
with napi.NominatimAPI(args.project_dir) as api:
|
||||||
result = api.reverse(napi.Point(args.lon, args.lat),
|
result = api.reverse(napi.Point(args.lon, args.lat),
|
||||||
max_rank=zoom_to_rank(args.zoom or 18),
|
max_rank=zoom_to_rank(args.zoom or 18),
|
||||||
layers=_get_layers(args, napi.DataLayer.ADDRESS | napi.DataLayer.POI),
|
layers=_get_layers(args,
|
||||||
|
napi.DataLayer.ADDRESS | napi.DataLayer.POI),
|
||||||
address_details=True, # needed for display name
|
address_details=True, # needed for display name
|
||||||
geometry_output=_get_geometry_output(args),
|
geometry_output=_get_geometry_output(args),
|
||||||
geometry_simplification=args.polygon_threshold,
|
geometry_simplification=args.polygon_threshold,
|
||||||
@@ -323,7 +324,7 @@ class APILookup:
|
|||||||
|
|
||||||
places = [napi.OsmID(o[0], int(o[1:])) for o in args.ids]
|
places = [napi.OsmID(o[0], int(o[1:])) for o in args.ids]
|
||||||
|
|
||||||
api = napi.NominatimAPI(args.project_dir)
|
with napi.NominatimAPI(args.project_dir) as api:
|
||||||
results = api.lookup(places,
|
results = api.lookup(places,
|
||||||
address_details=True, # needed for display name
|
address_details=True, # needed for display name
|
||||||
geometry_output=_get_geometry_output(args),
|
geometry_output=_get_geometry_output(args),
|
||||||
@@ -410,7 +411,7 @@ class APIDetails:
|
|||||||
raise UsageError('One of the arguments --node/-n --way/-w '
|
raise UsageError('One of the arguments --node/-n --way/-w '
|
||||||
'--relation/-r --place_id/-p is required/')
|
'--relation/-r --place_id/-p is required/')
|
||||||
|
|
||||||
api = napi.NominatimAPI(args.project_dir)
|
with napi.NominatimAPI(args.project_dir) as api:
|
||||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||||
result = api.details(place,
|
result = api.details(place,
|
||||||
address_details=args.addressdetails,
|
address_details=args.addressdetails,
|
||||||
@@ -465,7 +466,8 @@ class APIStatus:
|
|||||||
raise UsageError(f"Unsupported format '{args.format}'. "
|
raise UsageError(f"Unsupported format '{args.format}'. "
|
||||||
'Use --list-formats to see supported formats.')
|
'Use --list-formats to see supported formats.')
|
||||||
|
|
||||||
status = napi.NominatimAPI(args.project_dir).status()
|
with napi.NominatimAPI(args.project_dir) as api:
|
||||||
|
status = api.status()
|
||||||
|
|
||||||
if args.format == 'debug':
|
if args.format == 'debug':
|
||||||
print(loglib.get_and_disable())
|
print(loglib.get_and_disable())
|
||||||
|
|||||||
Reference in New Issue
Block a user