1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Classes and function related to status call.
10 from typing import Optional
14 import sqlalchemy as sa
16 from .connection import SearchConnection
17 from .version import NOMINATIM_API_VERSION
20 @dataclasses.dataclass
22 """ Result of a call to the status API.
26 software_version = NOMINATIM_API_VERSION
27 data_updated: Optional[dt.datetime] = None
28 database_version: Optional[str] = None
31 async def get_status(conn: SearchConnection) -> StatusResult:
32 """ Execute a status API call.
34 status = StatusResult(0, 'OK')
37 sql = sa.select(conn.t.import_status.c.lastimportdate).limit(1)
38 status.data_updated = await conn.scalar(sql)
40 if status.data_updated is not None:
41 if status.data_updated.tzinfo is None:
42 status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
44 status.data_updated = status.data_updated.astimezone(dt.timezone.utc)
48 status.database_version = await conn.get_property('database_version')