本文整理匯總了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