当前位置: 首页>>代码示例>>Python>>正文


Python requests_cache.CachedSession方法代码示例

本文整理汇总了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 = {} 
开发者ID:a4k-openproject,项目名称:plugin.video.openmeta,代码行数:20,代码来源:TheTVDB.py

示例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,
        ) 
开发者ID:panodata,项目名称:dwdweather2,代码行数:18,代码来源:client.py

示例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,)
        ) 
开发者ID:EmilStenstrom,项目名称:mybgg,代码行数:11,代码来源:bgg_client.py

示例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 
开发者ID:danvk,项目名称:oldnyc,代码行数:6,代码来源:url_fetcher.py

示例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 
开发者ID:jkwill87,项目名称:mnamer,代码行数:12,代码来源:utils.py

示例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 
开发者ID:dr-leo,项目名称:pandaSDMX,代码行数:29,代码来源:remote.py


注:本文中的requests_cache.CachedSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。