File size: 655 Bytes
ee29427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import asyncio
from abc import ABC, abstractmethod

class BaseAdapter(ABC):
    name: str = "Unknown"
    source_type: str = "stub"  # "live" or "stub"
    base_url: str = ""

    def __init__(self, rate_limit_seconds: float = 1.0):
        self._rate_limit = rate_limit_seconds
        self._last_call = 0

    async def _throttle(self):
        now = asyncio.get_event_loop().time()
        elapsed = now - self._last_call
        if elapsed < self._rate_limit:
            await asyncio.sleep(self._rate_limit - elapsed)
        self._last_call = asyncio.get_event_loop().time()

    @abstractmethod
    async def search(self, query: str):
        pass