-class SimaFM():
- """
- """
- root_url = 'http://{host}/api/{version}'.format(**ECH)
- cache = dict({})
- timestamp = datetime.utcnow()
-
- def __init__(self, cache=True):
- self._ressource = None
- self._payload = {'api_key': ECH.get('apikey')}
- self.current_element = None
- self.caching = cache
- self.purge_cache()
-
- def _fetch(self):
- """Use cached elements or proceed http request"""
- self._req = get(self._ressource, params=self._payload, timeout=5)
- if self._req.url in SimaFM.cache:
- print('got from SimaFM cache')
- self.current_element = SimaFM.cache.get(self._req.url).get()
- return
- self._fetch_lfm()
-
- @Throttle(WAIT_BETWEEN_REQUESTS)
- def _fetch_lfm(self):
- """fetch from web service"""
- if self._req.status_code is not 200:
- raise SimaEchoError(self._req.status_code)
- self.current_element = self._req.json()
- self._controls_lfm_answer()
- if self.caching:
- SimaFM.cache.update({self._req.url:
- Cache(self.current_element)})
-
- def _controls_lfm_answer(self):
- """Controls last.fm answer.