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)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from aiocache import cached
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from gallery.sketch.schedule.api import ScheduleApi
|
||||
@@ -13,8 +12,8 @@ logger = logging.getLogger("matchtv")
|
||||
|
||||
|
||||
class MatchTvApi(ScheduleApi):
|
||||
PROVIDER = "matchtv"
|
||||
SOURCE = ApiSource("https://matchtv.ru")
|
||||
CACHE_TTL = 30 * 60
|
||||
|
||||
async def get_channels(self) -> list[str]:
|
||||
return [
|
||||
@@ -27,7 +26,6 @@ class MatchTvApi(ScheduleApi):
|
||||
ChannelId.MATCH_STRANA,
|
||||
]
|
||||
|
||||
@cached(ttl=CACHE_TTL)
|
||||
async def get_channel_schedule(
|
||||
self, channel_id: str, date: datetime.date
|
||||
) -> Schedule:
|
||||
|
||||
Reference in New Issue
Block a user