コード例 #1
0
 def __get_weather(self):
     dk = DarkSky()
     if dk.is_success():
         logger.info('API success on attempt: ' + str(self.api_tries) + ' current_temp: ' + str(dk.current_temp()) + ' todays_low: ' +
                     str(dk.todays_low()) + ' todays_high: ' + str(dk.todays_high()) + ' icon: ' + str(dk.icon()))
         self.current_temp = dk.current_temp()
         self.todays_low = dk.todays_low()
         self.todays_high = dk.todays_high()
         self.icon = dk.icon()
         self.api_tries = 0
     else:
         self.api_tries += 1
         if self.api_tries >= DATA_DELAY_REFRESH_LIMIT or self.current_temp is None:
             self.__reset_os_network_interface()
             now = datetime.datetime.now()
             try_again_time = now + datetime.timedelta(seconds=CALL_INTERVAL_SECONDS)
             logger.warning(
                 "failed to get weather data after " + str(self.api_tries) + " attempt(s). Will try again in " + str(round(CALL_INTERVAL_SECONDS/60)) + " minutes (at " + try_again_time.strftime("%d-%b-%y %H:%M:%S") + ")"
             )
             self.__display_data_failure(try_again_time)
             time.sleep(CALL_INTERVAL_SECONDS)
             self.matrix.Clear()
             self.__get_weather()
         else:
             logger.warning("Attempt: " + str(self.api_tries) + ". Will try again in " + str(round(CALL_INTERVAL_SECONDS/60)) + " minutes to update weather data. Displaying old data.")
             pass
     self.matrix.Clear()