Python requests_cache.CachedSession() Examples
The following are 6
code examples of requests_cache.CachedSession().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
requests_cache
, or try the search function
.
Example #1
Source File: TheTVDB.py From plugin.video.openmeta with GNU General Public License v3.0 | 6 votes |
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 = {}
Example #2
Source File: client.py From dwdweather2 with MIT License | 6 votes |
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, )
Example #3
Source File: bgg_client.py From mybgg with MIT License | 5 votes |
def __init__(self, path, ttl): self.cache = CachedSession( cache_name=path, backend="sqlite", expire_after=ttl, extension="", fast_save=True, allowable_codes=(200,) )
Example #4
Source File: url_fetcher.py From oldnyc with Apache License 2.0 | 5 votes |
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
Example #5
Source File: utils.py From mnamer with MIT License | 5 votes |
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
Example #6
Source File: remote.py From pandaSDMX with Apache License 2.0 | 5 votes |
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