Пример #1
0
    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
Пример #2
0
    def get_all_regions(self):
        '''
        Request a list of regions from Datapoint. Returns each Region
        as a Site object. Regions rarely change, so we cache the response
        for one hour to minimise requests to API.
        '''
        if (time() - self.regions_last_update) < self.regions_update_time:
            return self.regions_last_request

        response = self.call_api(self.all_regions_path)
        regions = []
        for location in response['Locations']['Location']:
            region = Site()
            region.id = location['@id']
            region.region = location['@name']
            region.name = REGION_NAMES[location['@name']]
            regions.append(region)

        self.regions_last_update = time()
        self.regions_last_request = regions
        return regions
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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