Skip to content
Snippets Groups Projects
Commit 6f9416d7 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

Fixed #10 - prevent fetching weather data too often

parent c1adf7b0
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,7 @@ def join_url_parts(*args: str) -> str:
def round_to_decimals(value, decimals) -> str:
return '{:.{}f}'.format(value, decimals)
def determine_weather_cache_key(lat: float, lon: float):
return f'weather_{lat}_{lon}'
......@@ -14,7 +14,7 @@ class CurrentTemperatureTile(Tile):
def fetch(self, pageName: str) -> Dict:
weatherService = ServiceManager.get_instance().get_service_by_type_name('WeatherService')
cacheKey = f'{pageName}_{self._uniqueName}'
cacheKey = Helpers.determine_weather_cache_key(self._settings['lat'], self._settings['lon'])
fetchIntervalInSeconds = 60 * 10 # query api less often
weatherData = weatherService.get_data(cacheKey, fetchIntervalInSeconds, self._settings)
......
......@@ -18,7 +18,7 @@ class SevenDaysForecastTile(Tile):
def fetch(self, pageName: str) -> Dict:
weatherService = ServiceManager.get_instance().get_service_by_type_name('WeatherService')
cacheKey = f'{pageName}_{self._uniqueName}'
cacheKey = Helpers.determine_weather_cache_key(self._settings['lat'], self._settings['lon'])
fetchIntervalInSeconds = 60 * 10 # query api less often
weatherData = weatherService.get_data(cacheKey, fetchIntervalInSeconds, self._settings)
......@@ -32,7 +32,6 @@ class SevenDaysForecastTile(Tile):
date = datetime.strftime(date, self.DATE_FORMAT)
forecastData[date] = (int(day['temp']['min']), int(day['temp']['max']))
formattedDates = [f'<b>{value}</b>' for value in forecastData.keys()]
minValues = [x[0] for x in forecastData.values()]
maxValues = [x[1] for x in forecastData.values()]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment