diff --git a/meteofrance/client.py b/meteofrance/client.py index 3647ee9..55e0cfb 100644 --- a/meteofrance/client.py +++ b/meteofrance/client.py @@ -228,15 +228,17 @@ def _format_data(self): try: forecast = {} forecast["date"] = daydata.find("a").string - forecast["weather"] = daydata.find("dd").string.strip() - min_temp = re.sub(r"[^0-9\-]","",daydata.find(class_="min-temp").string) - if min_temp != '-': - forecast["min_temp"] = int(min_temp) - max_temp = re.sub(r"[^0-9\-]","",daydata.find(class_="max-temp").string) - if max_temp != '-': - forecast["max_temp"] = int(max_temp) - forecast["weather_class"] = daydata.find("dd").attrs['class'][1] - self._data["forecast"][day] = forecast + weather = daydata.find("dd").string + if weather: + forecast["weather"] = weather.strip() + min_temp = re.sub(r"[^0-9\-]","",daydata.find(class_="min-temp").string) + if min_temp != '-': + forecast["min_temp"] = int(min_temp) + max_temp = re.sub(r"[^0-9\-]","",daydata.find(class_="max-temp").string) + if max_temp != '-': + forecast["max_temp"] = int(max_temp) + forecast["weather_class"] = daydata.find("dd").attrs['class'][1] + self._data["forecast"][day] = forecast day = day + 1 except: raise diff --git a/test.py b/test.py index e7433aa..e27e104 100644 --- a/test.py +++ b/test.py @@ -94,7 +94,7 @@ def test_pointe_a_pitre(self): self.assertNotIn('next_rain_datetime', data) self.assertNotIn('rain_forecast_text', data) self.assertNotIn('rain_forecast', data) - self.assertEqual(len(data['forecast']), 10) + self.assertGreaterEqual(len(data['forecast']), 9) # Same with world data def test_pointe_a_pitre(self): @@ -120,7 +120,7 @@ def test_pointe_a_pitre(self): self.assertNotIn('next_rain', data) self.assertNotIn('rain_forecast_text', data) self.assertNotIn('rain_forecast', data) - self.assertEqual(len(data['forecast']), 10) + self.assertGreaterEqual(len(data['forecast']), 9) class TestRainForecast(unittest.TestCase): def test_rain_forecast_is_updated(self):