From d0f7161ef9a0a7af4b363bba5417200b7d74880b Mon Sep 17 00:00:00 2001 From: Katrijne Deckers Date: Mon, 11 Mar 2024 15:24:39 +0100 Subject: [PATCH] fix: update get_meteo for belgian fields --- pywig/__init__.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pywig/__init__.py b/pywig/__init__.py index 460ee48..5fb800e 100644 --- a/pywig/__init__.py +++ b/pywig/__init__.py @@ -58,20 +58,19 @@ def get_meteo(self, field_id: str, key: str, start_date: datetime.date = None, e :rtype: List """ field = self.get_field_details(field_id) - if field.meteo: - if key.lower() in field.meteo: - meteo = list(map(lambda x: MeteoStat(date=x['date'], value=x['value']), field.meteo[key.lower()])) - if start_date: - meteo = [x for x in meteo if start_date <= datetime.datetime.strptime(x.date, "%Y-%m-%d").date()] - if end_date: - meteo = [x for x in meteo if datetime.datetime.strptime(x.date, "%Y-%m-%d").date() <= end_date] - return meteo - else: - raise Exception( - f'Meteo statistic {key} is not supported for this field, only {",".join(field.meteo.keys())}') - else: + if field.meteo and key.lower() in field.meteo: + meteo = list(map(lambda x: MeteoStat(date=x['date'], value=x['value']), field.meteo[key.lower()])) + if start_date: + meteo = [x for x in meteo if start_date <= datetime.datetime.strptime(x.date, "%Y-%m-%d").date()] + if end_date: + meteo = [x for x in meteo if datetime.datetime.strptime(x.date, "%Y-%m-%d").date() <= end_date] + return meteo + elif field.metadata.country == 'Belgium': start_date = start_date.isoformat() if start_date else field.metadata['startDate'] end_date = end_date.isoformat() if end_date else field.metadata['endDate'] return self._api.get_meteo_data(geometry=field.metadata['geometry'], key=key, start_date=start_date, end_date=end_date) + else: + raise Exception( + f'Meteo statistic {key} is not supported for this field, only {",".join(field.meteo.keys())}')