feat: add redis cache
This commit is contained in:
@@ -2,7 +2,6 @@ import datetime
|
||||
import logging
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from aiocache import cached
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from gallery.sketch.source import ApiSource
|
||||
@@ -17,6 +16,7 @@ logger = logging.getLogger("gismeteo")
|
||||
|
||||
|
||||
class GismeteoApi(WeatherApi):
|
||||
PROVIDER = "gismeteo"
|
||||
SOURCE = ApiSource(
|
||||
"https://www.gismeteo.ru",
|
||||
cookies={
|
||||
@@ -32,7 +32,6 @@ class GismeteoApi(WeatherApi):
|
||||
)
|
||||
},
|
||||
)
|
||||
CACHE_TTL = 10 * 60
|
||||
|
||||
def _parse_oneday(self, date: datetime.date, data: str) -> WeatherResponse:
|
||||
result: List[Dict[str, Any]] = []
|
||||
@@ -76,12 +75,10 @@ class GismeteoApi(WeatherApi):
|
||||
LocationId.ZMIYEVKA,
|
||||
]
|
||||
|
||||
@cached(ttl=CACHE_TTL)
|
||||
async def get_day(self, location_id: str, date: datetime.date) -> WeatherResponse:
|
||||
data = await self.SOURCE.request(f"weather-{location_id}/{datehelp.dump(date)}")
|
||||
return self._parse_oneday(date, data)
|
||||
|
||||
@cached(ttl=CACHE_TTL)
|
||||
async def get_days(self, location_id: str, days: int) -> WeatherResponse:
|
||||
data = await self.SOURCE.request(f"weather-{location_id}/{days}-days")
|
||||
return self._parse_manydays(data)
|
||||
|
||||
Reference in New Issue
Block a user