forked from hans/Nominatim
implement command line status call in Python
This commit is contained in:
36
nominatim/result_formatter/v1.py
Normal file
36
nominatim/result_formatter/v1.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# This file is part of Nominatim. (https://nominatim.org)
|
||||
#
|
||||
# Copyright (C) 2022 by the Nominatim developer community.
|
||||
# For a full list of authors see the git log.
|
||||
"""
|
||||
Output formatters for API version v1.
|
||||
"""
|
||||
from typing import Dict, Any
|
||||
from collections import OrderedDict
|
||||
import json
|
||||
|
||||
from nominatim.result_formatter.base import FormatDispatcher
|
||||
from nominatim.apicmd.status import StatusResult
|
||||
|
||||
create = FormatDispatcher()
|
||||
|
||||
@create.format_func(StatusResult, 'text')
|
||||
def _format_status_text(result: StatusResult) -> str:
|
||||
return result.message
|
||||
|
||||
|
||||
@create.format_func(StatusResult, 'json')
|
||||
def _format_status_json(result: StatusResult) -> str:
|
||||
# XXX write a simple JSON serializer
|
||||
out: Dict[str, Any] = OrderedDict()
|
||||
out['status'] = result.status
|
||||
out['message'] = result.message
|
||||
if result.data_updated is not None:
|
||||
out['data_updated'] = result.data_updated
|
||||
out['software_version'] = result.software_version
|
||||
if result.database_version is not None:
|
||||
out['database_version'] = result.database_version
|
||||
|
||||
return json.dumps(out)
|
||||
Reference in New Issue
Block a user