From 8086c6b13c92f5fc520deb926b0ad9df70ef5c84 Mon Sep 17 00:00:00 2001 From: gtitov Date: Sat, 6 Nov 2021 18:27:30 +0300 Subject: [PATCH] Add endpoint 'get_one_station_dates' --- main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.py b/main.py index 53e800d..8d87fc7 100644 --- a/main.py +++ b/main.py @@ -180,6 +180,32 @@ async def get_one_station_values(station_id: int, start_datetime: datetime, end_ for row in one_station_values ] +@app.get("/station/{station_id}/dates") +async def get_one_station_dates(station_id: int): + """Возращает даты, для которых на данной станции есть данные. + """ + + # Wide form + cur.execute( + """SELECT + DISTINCT(date(datetime, 'unixepoch')) + FROM + stations_all_params + WHERE + station_id = :station_id + """, + { + "station_id": station_id + } + ) + + one_station_dates = cur.fetchall() + + return [ + row[0] + for row in one_station_dates + ] + @app.get("/stations/dates") async def get_stations_dates(): """Возращает минимальную и максимальную даты, которые есть в таблице сетки.