1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2023 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Output formatters for API version v1.
10 from typing import Dict, Any
11 from collections import OrderedDict
14 from nominatim.result_formatter.base import FormatDispatcher
15 from nominatim.api import StatusResult
17 create = FormatDispatcher()
19 @create.format_func(StatusResult, 'text')
20 def _format_status_text(result: StatusResult) -> str:
22 return f"ERROR: {result.message}"
27 @create.format_func(StatusResult, 'json')
28 def _format_status_json(result: StatusResult) -> str:
29 out: Dict[str, Any] = OrderedDict()
30 out['status'] = result.status
31 out['message'] = result.message
32 if result.data_updated is not None:
33 out['data_updated'] = result.data_updated.isoformat()
34 out['software_version'] = str(result.software_version)
35 if result.database_version is not None:
36 out['database_version'] = str(result.database_version)
38 return json.dumps(out)