當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。