Skip to content

Commit

Permalink
fix: update get_meteo for belgian fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrijne-at-Vito committed Mar 11, 2024
1 parent 2752fc5 commit d0f7161
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions pywig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())}')

0 comments on commit d0f7161

Please sign in to comment.