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, NominatimVersion, parse_version
19 @dataclasses.dataclass
21 """ Result of a call to the status API.
25 software_version = NOMINATIM_API_VERSION
26 data_updated: Optional[dt.datetime] = None
27 database_version: Optional[NominatimVersion] = None
30 async def get_status(conn: SearchConnection) -> StatusResult:
31 """ Execute a status API call.
33 status = StatusResult(0, 'OK')
36 sql = sa.select(conn.t.import_status.c.lastimportdate).limit(1)
37 status.data_updated = await conn.scalar(sql)
39 if status.data_updated is not None:
40 if status.data_updated.tzinfo is None:
41 status.data_updated = status.data_updated.replace(tzinfo=dt.timezone.utc)
43 status.data_updated = status.data_updated.astimezone(dt.timezone.utc)
47 status.database_version = parse_version(await conn.get_property('database_version'))