示例#1
0
 def import_meals(self):
     """Import meal data from provider
     """
     meals = self.provider.import_meals()
     data = json.dumps([meal.as_dict() for meal in meals])
     kv_store.set(self._get_key(KEY_MEAL), data)
     self._set_last_updated()
示例#2
0
 def import_meals(self):
     """Import meal data from provider
     """
     meals = self.provider.import_meals()
     data = json.dumps([meal.as_dict() for meal in meals])
     kv_store.set(self._get_key(KEY_MEAL), data)
     self._set_last_updated()
示例#3
0
 def import_forecasts(self):
     """Import forecasts data from provider
     """
     forecasts = self.provider.import_forecasts()
     data = json.dumps([forecast.as_dict() for forecast in forecasts])
     kv_store.set(self._get_key(KEY_FORECASTS), data)
     self._set_last_updated()
示例#4
0
def cache_etag_location(url, etag, location):
    resource_etag_key = ETAG_KEY_FORMAT % (__name__, url)
    resource_location_key = LOCATION_KEY_FORMAT % (__name__, url)
    success = False
    if etag and location:
        kv_store.set(resource_etag_key, etag)
        kv_store.set(resource_location_key, location)
        success = True
    return success
示例#5
0
 def import_data(self):
     try:
         response = requests.get(self.url, timeout=self.timeout)
         response.raise_for_status()
     except RequestException as re:
         logger.warning('Error in request to Park & Ride info', exc_info=True,
                        extra={
                            'data': {
                                'url': self.url}
                        })
         raise ProviderException
     else:
         data = self.parse_html(response.text)
         kv_store.set(CACHE_KEY, json.dumps(data))
         kv_store.set(CACHE_KEY_UPDATE, datetime.now().isoformat())
示例#6
0
 def set_status(self, status_map):
     last_updated = datetime.now()
     kv_store.set(self.last_updated_key, last_updated)
     return kv_store.hmset(self.hmap_key, status_map)
示例#7
0
 def _set_last_updated(self):
     """Set the last updated date to now
     """
     kv_store.set(self._get_key(KEY_UPDATED), datetime.now().isoformat())
示例#8
0
 def _set_last_updated(self):
     """Set the last updated date to now
     """
     kv_store.set(self._get_key(KEY_UPDATED), datetime.now().isoformat())
示例#9
0
 def set_status(self, status_map):
     last_updated = datetime.now()
     kv_store.set(self.last_updated_key, last_updated)
     return kv_store.hmset(self.hmap_key, status_map)
示例#10
0
 def import_observation(self):
     """Import observation data from provider
     """
     observation = self.provider.import_observation()
     kv_store.set(self._get_key(KEY_OBSERVATION), json.dumps(observation.as_dict()))
     self._set_last_updated()