ZeevG/python-forecast.io

Question: Rational behind second API call?

Closed this issue · 1 comments

I was wondering what was the rationale behind this second API call? When the key is not in response json wont that mean data is not available? Thanks for clarifying.

   def _forcastio_data(self, key):
        keys = ['minutely', 'currently', 'hourly', 'daily']
        try:
            if key not in self.json:
                keys.remove(key)
                url = "%s&exclude=%s%s" % (self.response.url.split('&')[0],
                      ','.join(keys), ',alerts,flags')

                response = requests.get(url).json()
                self.json[key] = response[key]

            if key == 'currently':
                return ForecastioDataPoint(self.json[key])
            else:
                return ForecastioDataBlock(self.json[key])
ZeevG commented

Hi,

The second (or more) API calls is used only when lazy=True. See the docs here. https://github.com/ZeevG/python-forecast.io#function-forecastioload_forecastkey-latitude-longitude

Lazy mode means that data will be requested from the API as each time period is requested.