|
1 | 1 | import datetime |
2 | | -from platform import python_version |
3 | 2 |
|
4 | 3 | from datapoint.exceptions import APIException |
5 | 4 | from datapoint.weather_codes import WEATHER_CODES |
@@ -110,21 +109,13 @@ def __init__(self, frequency, api_data): |
110 | 109 | :type api_data: dict |
111 | 110 | """ |
112 | 111 | self.frequency = frequency |
113 | | - if python_version() < "3.11": |
114 | | - # Need to parse format like 2024-02-17T15:00Z. This can only be |
115 | | - # done with datetime.datetime.fromisoformat from python 3.11 |
116 | | - # onwards. Using this if statement to remember to remove the |
117 | | - # explicit strptime in the future, and it annoyed me that |
118 | | - # fromisoformat couldn't handle all iso-formatted datetimes. |
119 | | - data_date = datetime.datetime.strptime( |
120 | | - api_data["features"][0]["properties"]["modelRunDate"], |
121 | | - "%Y-%m-%dT%H:%M%z", |
122 | | - ) |
123 | | - else: |
124 | | - data_date = datetime.datetime.fromisoformat( |
125 | | - api_data["features"][0]["properties"]["modelRunDate"] |
126 | | - ) |
127 | | - self.data_date = data_date #: The date the provided forecast was generated. |
| 112 | + # Need to parse format like 2024-02-17T15:00Z. This can only be |
| 113 | + # done with datetime.datetime.fromisoformat from python 3.11 |
| 114 | + # onwards. |
| 115 | + self.data_date = datetime.datetime.strptime( |
| 116 | + api_data["features"][0]["properties"]["modelRunDate"], |
| 117 | + "%Y-%m-%dT%H:%M%z", |
| 118 | + ) #: The date the provided forecast was generated. |
128 | 119 |
|
129 | 120 | self.forecast_longitude = api_data["features"][0]["geometry"]["coordinates"][ |
130 | 121 | 0 |
@@ -173,30 +164,16 @@ def _build_timesteps_from_daily(self, forecasts, parameters): |
173 | 164 |
|
174 | 165 | timesteps = [] |
175 | 166 | for forecast in forecasts: |
176 | | - if python_version() < "3.11": |
177 | | - # Need to parse format like 2024-02-17T15:00Z. This can only be |
178 | | - # done with datetime.datetime.fromisoformat from python 3.11 |
179 | | - # onwards. Using this if statement to remember to remove the |
180 | | - # explicit strptime in the future, and it annoyed me that |
181 | | - # fromisoformat couldn't handle all iso-formatted datetimes. |
182 | | - night_step = { |
183 | | - "time": datetime.datetime.strptime( |
184 | | - forecast["time"], "%Y-%m-%dT%H:%M%z" |
185 | | - ) |
186 | | - } |
187 | | - day_step = { |
188 | | - "time": datetime.datetime.strptime( |
189 | | - forecast["time"], "%Y-%m-%dT%H:%M%z" |
190 | | - ) |
191 | | - + datetime.timedelta(hours=12) |
192 | | - } |
193 | | - |
194 | | - else: |
195 | | - night_step = {"time": datetime.datetime.fromisoformat(forecast["time"])} |
196 | | - day_step = { |
197 | | - "time": datetime.datetime.fromisoformat(forecast["time"]) |
198 | | - + datetime.timedelta(hours=12) |
199 | | - } |
| 167 | + # Need to parse format like 2024-02-17T15:00Z. This can only be |
| 168 | + # done with datetime.datetime.fromisoformat from python 3.11 |
| 169 | + # onwards. |
| 170 | + night_step = { |
| 171 | + "time": datetime.datetime.strptime(forecast["time"], "%Y-%m-%dT%H:%M%z") |
| 172 | + } |
| 173 | + day_step = { |
| 174 | + "time": datetime.datetime.strptime(forecast["time"], "%Y-%m-%dT%H:%M%z") |
| 175 | + + datetime.timedelta(hours=12) |
| 176 | + } |
200 | 177 |
|
201 | 178 | for element, value in forecast.items(): |
202 | 179 | if element.startswith("midday"): |
@@ -260,17 +237,12 @@ def _build_timestep(self, forecast, parameters): |
260 | 237 | timestep = {} |
261 | 238 | for element, value in forecast.items(): |
262 | 239 | if element == "time": |
263 | | - if python_version() < "3.11": |
264 | | - # Need to parse format like 2024-02-17T15:00Z. This can only be |
265 | | - # done with datetime.datetime.fromisoformat from python 3.11 |
266 | | - # onwards. Using this if statement to remember to remove the |
267 | | - # explicit strptime in the future, and it annoyed me that |
268 | | - # fromisoformat couldn't handle all iso-formatted datetimes. |
269 | | - timestep["time"] = datetime.datetime.strptime( |
270 | | - forecast["time"], "%Y-%m-%dT%H:%M%z" |
271 | | - ) |
272 | | - else: |
273 | | - timestep["time"] = datetime.datetime.fromisoformat(forecast["time"]) |
| 240 | + # Need to parse format like 2024-02-17T15:00Z. This can only be |
| 241 | + # done with datetime.datetime.fromisoformat from python 3.11 |
| 242 | + # onwards. |
| 243 | + timestep["time"] = datetime.datetime.strptime( |
| 244 | + forecast["time"], "%Y-%m-%dT%H:%M%z" |
| 245 | + ) |
274 | 246 |
|
275 | 247 | elif element == "significantWeatherCode": |
276 | 248 | timestep[element] = { |
|
0 commit comments