import json import os from bootstrap import build_client from automapa_map_services.adapter.google_geocode import GoogleGeocodeAdapter from automapa_map_services.exceptions import AutomapaException def read_location(data): if data.get("status") == "ZERO_RESULTS": return {"status": "NO_RESULTS"} if data.get("status") != "OK": raise RuntimeError("UNEXPECTED_STATUS") if not data.get("results"): return {"status": "NO_RESULTS"} first = data["results"][0] location = first["geometry"]["location"] return {"status": "OK", "lat": location["lat"], "lng": location["lng"], "address": first["formatted_address"]} def migrate(client): adapter = GoogleGeocodeAdapter(client) text = adapter.geocode({"address": "Domaniewska 37, Warszawa"}) components = adapter.geocode({ "components": "locality:Warszawa|route:Domaniewska|street_number:37|country:PL" }) native_input = client.geocoder().geocode( city="Warszawa", street="Domaniewska", house="37", country="PL", extra={"format": "google"}, ).data() return [read_location(data) for data in (text, components, native_input)] if __name__ == "__main__": try: client = build_client(os.environ.get("AUTOMAPA_SESSION_ID", "")) print(json.dumps(migrate(client))) except (AutomapaException, RuntimeError, ValueError): raise SystemExit("SDK_ERROR_OR_SESSION_REQUIRED")