def discover( ctx, query, coordinates, radius, country_codes, bounding_box, limit, lang, apikey, raw, display, ): """ Search places using free-form text query. There are multiple combination of inputs for restricting your search - ``center`` and ``country_code`` - ``center`` and ``radius`` - ``bounding_box`` \f :param ctx: :param query: :param coordinates: :param radius: :param country_codes: :param bounding_box: :param limit: :param lang: :param apikey: :param raw: :param display: :return: """ apikey = apikey or os.environ.get("HERE_APIKEY") if apikey is None: raise ApiKeyNotFoundError( "Please pass HERE API KEY as --apikey or set it as environment " "variable in HERE_APIKEY " ) ctx.obj["apikey"] = apikey ls = LS(api_key=apikey) result = ls.discover( query=query, center=coordinates.split(",")[::-1] if coordinates else coordinates, radius=radius, country_codes=country_codes.split(",") if country_codes else country_codes, bounding_box=bounding_box.split(",") if bounding_box else bounding_box, limit=limit, lang=lang, ) if raw: click.secho(json.dumps(result.response, indent=2), fg="green") elif display: geo_display(json.dumps(result.to_geojson(), indent=2)) else: click.secho(json.dumps(result.items, indent=2), fg="green")
def test_ls_discover(): ls = LS(api_key=LS_API_KEY) result = ls.discover(query="starbucks", center=[19.1663, 72.8526], radius=10000, lang="en") assert len(result.items) == 20 result2 = ls.discover( query="starbucks", center=[19.1663, 72.8526], country_codes=["IND"], limit=2, ) assert len(result2.items) == 2 result3 = ls.discover( query="starbucks", bounding_box=[13.08836, 52.33812, 13.761, 52.6755], ) assert len(result3.items) == 20 with pytest.raises(ValueError): ls.discover( query="starbucks", center=[52.5, 13.4], bounding_box=[13.08836, 52.33812, 13.761, 52.6755], ) with pytest.raises(ApiError): ls2 = LS(api_key="dummy") ls2.discover(query="starbucks", center=[19.1663, 72.8526], radius=10000, limit=10)