本文整理汇总了Python中requests_cache.CachedSession方法的典型用法代码示例。如果您正苦于以下问题:Python requests_cache.CachedSession方法的具体用法?Python requests_cache.CachedSession怎么用?Python requests_cache.CachedSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests_cache
的用法示例。
在下文中一共展示了requests_cache.CachedSession方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def __init__(self, language='en'):
languages = ['da', 'fi', 'nl', 'de', 'it', 'es', 'fr', 'pl', 'hu',
'el', 'tr', 'ru', 'he', 'ja', 'pt', 'zh', 'cs', 'sl',
'hr', 'ko', 'sv', 'no']
config = {}
config['apikey'] = API_key
if language in languages:
config['language'] = language
else:
config['language'] = 'en'
config['url_search'] = u'https://thetvdb.com/api/GetSeries.php?seriesname=%%s&language=%%s' % config
config['url_search_by_imdb'] = u'https://thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=%%s&language=%%s' % config
config['url_sid_full'] = u'https://thetvdb.com/api/%(apikey)s/series/%%s/all/%%s.zip' % config
config['url_sid_base'] = u'https://thetvdb.com/api/%(apikey)s/series/%%s/%%s.xml' % config
config['url_artwork_prefix'] = u'https://thetvdb.com/banners/%%s' % config
self.config = config
self.session = requests_cache.CachedSession(expire_after=21600, backend='sqlite', cache_name=os.path.join(plugin.storage_path, 'TheTVDB'))
self.shows = {}
示例2: setup_cache
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def setup_cache(self):
"""Setup HTTP client cache"""
# Configure User-Agent string.
user_agent = APP_NAME + "/" + APP_VERSION
# Use hostname of url as cache prefix.
cache_name = urlparse(self.uri).netloc
# Configure cached requests session.
self.http = CachedSession(
backend="sqlite",
cache_name=os.path.join(self.cache_path, cache_name),
expire_after=self.cache_ttl,
user_agent=user_agent,
)
示例3: __init__
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def __init__(self, path, ttl):
self.cache = CachedSession(
cache_name=path,
backend="sqlite",
expire_after=ttl,
extension="",
fast_save=True,
allowable_codes=(200,)
)
示例4: __init__
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def __init__(self, throttle_secs=1.0):
self._session = requests_cache.CachedSession('.url_fetcher_cache')
self._throttle_secs = throttle_secs
self._last_fetch = 0.0
示例5: get_session
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def get_session() -> requests_cache.CachedSession:
"""Convenience function that returns request-cache session singleton."""
if not hasattr(get_session, "session"):
get_session.session = requests_cache.CachedSession(
cache_name=str(CACHE_PATH), expire_after=518_400 # 6 days
)
adapter = HTTPAdapter(max_retries=3)
get_session.session.mount("http://", adapter)
get_session.session.mount("https://", adapter)
return get_session.session
示例6: __init__
# 需要导入模块: import requests_cache [as 别名]
# 或者: from requests_cache import CachedSession [as 别名]
def __init__(self, timeout=30.1, proxies=None, stream=False, **kwargs):
if MaybeCachedSession is not requests.Session:
# Using requests_cache.CachedSession
# No cache keyword arguments supplied = don't use the cache
disabled = set(kwargs.keys()) <= {'get_footer_url'}
if disabled:
# Avoid creating any file
kwargs['backend'] = 'memory'
super(Session, self).__init__(**kwargs)
# Overwrite value from requests_cache.CachedSession.__init__()
self._is_cache_disabled = disabled
elif len(kwargs):
raise ValueError('Cache arguments have no effect without '
'requests_session: %s' % kwargs)
else:
# Plain requests.Session
super(Session, self).__init__()
# Overwrite values from requests.Session.__init__()
self.proxies = proxies
self.timeout = timeout
self.stream = stream