ZeevG / python-forecast.io

A thin Python Wrapper for the Dark Sky (formerly forecast.io) weather API
http://zeevgilovitz.com/python-forecast.io/
Other
424 stars 88 forks source link

Question: Rational behind second API call? #38

Closed ben-at-uptake closed 8 years ago

ben-at-uptake commented 8 years ago

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 8 years ago

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.