Skip to content

Commit

Permalink
Save all available forecast data, including today's
Browse files Browse the repository at this point in the history
  • Loading branch information
pguyot committed Oct 17, 2019
1 parent 4b0212d commit 014a658
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
13 changes: 9 additions & 4 deletions meteofrance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,21 @@ def _format_data(self):

self._data["forecast"] = {}
daydatas = soup.find(class_="liste-jours").find_all("li")
for day in range(0, 5):
day = 0
for daydata in daydatas:
try:
daydata = daydatas[day+1]
forecast = {}
forecast["date"] = daydata.find("a").string
forecast["weather"] = daydata.find("dd").string.strip()
forecast["min_temp"] = int(re.sub(r"[^0-9\-]","",daydata.find(class_="min-temp").string))
forecast["max_temp"] = int(re.sub(r"[^0-9\-]","",daydata.find(class_="max-temp").string))
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

Expand Down
28 changes: 28 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_beynost(self):
self.assertNotIn('next_rain_datetime', data)
self.assertNotIn('rain_forecast_text', data)
self.assertNotIn('rain_forecast', data)
self.assertEqual(len(data['forecast']), 14)

# pointe-a-pitre : result from meteo-france is different and it returns less data
def test_pointe_a_pitre(self):
Expand All @@ -93,6 +94,33 @@ 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)

# Same with world data
def test_pointe_a_pitre(self):
client = meteofranceClient('Tokyo')
client.need_rain_forecast = False
client.update()
data = client.get_data()
self.assertIn('name', data)
self.assertNotIn('dept', data)
self.assertIn('fetched_at', data)
self.assertIn('forecast', data)
self.assertNotIn('freeze_chance', data)
self.assertNotIn('rain_chance', data)
self.assertNotIn('snow_chance', data)
self.assertIn('temperature', data)
self.assertNotIn('thunder_chance', data)
self.assertNotIn('uv', data)
self.assertIn('weather_class', data)
self.assertIn('weather', data)
self.assertIn('wind_bearing', data)
self.assertIn('wind_speed', data)
self.assertNotIn('next_rain_intervals', data)
self.assertNotIn('next_rain', data)
self.assertNotIn('rain_forecast_text', data)
self.assertNotIn('rain_forecast', data)
self.assertEqual(len(data['forecast']), 10)

class TestRainForecast(unittest.TestCase):
def test_rain_forecast_is_updated(self):
Expand Down

0 comments on commit 014a658

Please sign in to comment.