yfinance-11.py
· 476 B · Python
原始檔案
from requests import Session
from requests_cache import CacheMixin, SQLiteCache
from requests_ratelimiter import LimiterMixin, MemoryQueueBucket
from pyrate_limiter import Duration, RequestRate, Limiter
class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
pass
session = CachedLimiterSession(
limiter=Limiter(RequestRate(2, Duration.SECOND*5)), # max 2 requests per 5 seconds
bucket_class=MemoryQueueBucket,
backend=SQLiteCache("yfinance.cache"),
)
1 | from requests import Session |
2 | from requests_cache import CacheMixin, SQLiteCache |
3 | from requests_ratelimiter import LimiterMixin, MemoryQueueBucket |
4 | from pyrate_limiter import Duration, RequestRate, Limiter |
5 | class CachedLimiterSession(CacheMixin, LimiterMixin, Session): |
6 | pass |
7 | |
8 | session = CachedLimiterSession( |
9 | limiter=Limiter(RequestRate(2, Duration.SECOND*5)), # max 2 requests per 5 seconds |
10 | bucket_class=MemoryQueueBucket, |
11 | backend=SQLiteCache("yfinance.cache"), |
12 | ) |