Skip to content

Commit

Permalink
Refactor get_forecast_for_future_hour to return dictionary instead of…
Browse files Browse the repository at this point in the history
… JSON string

- Refactored the get_forecast_for_future_hour method in class Location to return a dictionary directly instead of a JSON string.
- Bumped the version in setup.py to 1.1.0rc6 to reflect these improvements and changes.

This change improves the design of the Python package, making it easier to work with in other parts of the application and reducing potential errors related to JSON string handling.
  • Loading branch information
aschmere committed Jun 1, 2024
1 parent 33c4e05 commit fe97038
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions dwd_global_radiation/global_radiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def get_forecast_for_future_hour(self, datetime_input, number_of_hours):
retrieve the forecast.
Returns:
str: A JSON string containing the forecast timestamp in UTC and sis (Global Radiation)
value, or an error message if no forecast is found for the specified time.
dict: A dictionary containing the forecast timestamp in UTC and sis (Global Radiation)
value, or an error message if no forecast is found for the specified time.
"""
# Ensure datetime_input is in UTC
datetime_input = datetime_input.astimezone(timezone.utc)
Expand All @@ -145,16 +145,14 @@ def get_forecast_for_future_hour(self, datetime_input, number_of_hours):

if target_index < len(self.forecasts[0].entries):
forecast_entry = self.forecasts[0].entries[target_index]
return json.dumps(
{
"timestamp": datetime.fromtimestamp(
forecast_entry.timestamp, tz=timezone.utc
).strftime("%Y-%m-%dT%H:%M:%S%z"),
"sis": round(forecast_entry.sis),
}
)

return json.dumps({"error": "No forecast found for the specified time"})
return {
"timestamp": datetime.fromtimestamp(
forecast_entry.timestamp, tz=timezone.utc
).strftime("%Y-%m-%dT%H:%M:%S%z"),
"sis": round(forecast_entry.sis),
}

return {"error": "No forecast found for the specified time"}


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='dwd_global_radiation',
version='1.1.0rc5',
version='1.1.0rc6',
packages=find_packages(),
description='Access and analyze DWD global radiation data and forecasts',
long_description=long_description,
Expand Down

0 comments on commit fe97038

Please sign in to comment.