1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 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.apicmd.status import StatusResult
17 create = FormatDispatcher()
19 @create.format_func(StatusResult, 'text')
20 def _format_status_text(result: StatusResult) -> str:
24 @create.format_func(StatusResult, 'json')
25 def _format_status_json(result: StatusResult) -> str:
26 # XXX write a simple JSON serializer
27 out: Dict[str, Any] = OrderedDict()
28 out['status'] = result.status
29 out['message'] = result.message
30 if result.data_updated is not None:
31 out['data_updated'] = result.data_updated.isoformat()
32 out['software_version'] = result.software_version
33 if result.database_version is not None:
34 out['database_version'] = result.database_version
36 return json.dumps(out)