def get_observation_sites(self): """ This function returns a list of Site objects for which observations are available. """ if (time() - self.observation_sites_last_update) > self.observation_sites_update_time: self.observation_sites_last_update = time() data = self.__call_api("sitelist/", None, OBSERVATION_URL) sites = list() for jsoned in data['Locations']['Location']: site = Site() site.name = jsoned['name'] site.id = jsoned['id'] site.latitude = jsoned['latitude'] site.longitude = jsoned['longitude'] if 'region' in jsoned: site.region = jsoned['region'] if 'elevation' in jsoned: site.elevation = jsoned['elevation'] if 'unitaryAuthArea' in jsoned: site.unitaryAuthArea = jsoned['unitaryAuthArea'] if 'nationalPark' in jsoned: site.nationalPark = jsoned['nationalPark'] site.api_key = self.api_key sites.append(site) self.observation_sites_last_request = sites else: sites = observation_self.sites_last_request return sites
def get_observation_sites(self): """ This function returns a list of Site objects for which observations are available. """ if (time() - self.observation_sites_last_update) > self.observation_sites_update_time: self.observation_sites_last_update = time() data = self.__call_api("sitelist/", None, OBSERVATION_URL) sites = list() for jsoned in data['Locations']['Location']: site = Site() site.name = jsoned['name'] site.location_id = jsoned['id'] site.latitude = jsoned['latitude'] site.longitude = jsoned['longitude'] if 'region' in jsoned: site.region = jsoned['region'] if 'elevation' in jsoned: site.elevation = jsoned['elevation'] if 'unitaryAuthArea' in jsoned: site.unitaryAuthArea = jsoned['unitaryAuthArea'] if 'nationalPark' in jsoned: site.nationalPark = jsoned['nationalPark'] site.api_key = self.api_key sites.append(site) self.observation_sites_last_request = sites else: sites = self.observation_sites_last_request return sites
def get_all_sites(self): """ This function returns a list of Site object. """ if (time() - self.sites_last_update) > self.sites_update_time: self.sites_last_update = time() data = self.__call_api("sitelist/") sites = list() for jsoned in data['Locations']['Location']: site = Site() site.name = jsoned['name'] site.id = jsoned['id'] site.latitude = jsoned['latitude'] site.longitude = jsoned['longitude'] if 'region' in jsoned: site.region = jsoned['region'] if 'elevation' in jsoned: site.elevation = jsoned['elevation'] if 'unitaryAuthArea' in jsoned: site.elevation = jsoned['unitaryAuthArea'] if 'nationalPark' in jsoned: site.elevation = jsoned['nationalPark'] site.api_key = self.api_key sites.append(site) self.sites_last_request = sites else: sites = self.sites_last_request return sites
def get_forecast_sites(self): """ This function returns a list of Site object. """ time_now = time() if ( time_now - self.forecast_sites_last_update ) > self.forecast_sites_update_time or self.forecast_sites_last_request is None: data = self.__call_api("sitelist/") sites = list() for jsoned in data['Locations']['Location']: site = Site() site.name = jsoned['name'] site.id = jsoned['id'] site.latitude = jsoned['latitude'] site.longitude = jsoned['longitude'] if 'region' in jsoned: site.region = jsoned['region'] if 'elevation' in jsoned: site.elevation = jsoned['elevation'] if 'unitaryAuthArea' in jsoned: site.unitaryAuthArea = jsoned['unitaryAuthArea'] if 'nationalPark' in jsoned: site.nationalPark = jsoned['nationalPark'] site.api_key = self.api_key sites.append(site) self.forecast_sites_last_request = sites # Only set self.sites_last_update once self.sites_last_request has # been set self.forecast_sites_last_update = time_now else: sites = self.forecast_sites_last_request return sites
def get_forecast_sites(self): """ This function returns a list of Site object. """ time_now = time() if (time_now - self.forecast_sites_last_update) > self.forecast_sites_update_time or self.forecast_sites_last_request is None: data = self.__call_api("sitelist/") sites = list() for jsoned in data['Locations']['Location']: site = Site() site.name = jsoned['name'] site.id = jsoned['id'] site.latitude = jsoned['latitude'] site.longitude = jsoned['longitude'] if 'region' in jsoned: site.region = jsoned['region'] if 'elevation' in jsoned: site.elevation = jsoned['elevation'] if 'unitaryAuthArea' in jsoned: site.unitaryAuthArea = jsoned['unitaryAuthArea'] if 'nationalPark' in jsoned: site.nationalPark = jsoned['nationalPark'] site.api_key = self.api_key sites.append(site) self.forecast_sites_last_request = sites # Only set self.sites_last_update once self.sites_last_request has # been set self.forecast_sites_last_update = time_now else: sites = self.forecast_sites_last_request return sites