def read_config(self, file_='config.json'): config = tmod.open_json(file_) config_value = [value for (key, value) in sorted(config.items())] # icon_path api unit code self.api = config_value[0] self.code = config_value[2] self.icon_path = config_value[5] self.unit = config_value[8]
def get_weather_info(self): self.read_config() try: if self.api == True: f = requests.get( 'http://api.wunderground.com/api/{}/astronomy/forecast/conditions/q/pws:{}.json' .format(key, self.pws)) weather = f.json() tmod.save_json('weather.json', weather, 'home') self.weather = tmod.open_json('weather.json', 'home') self.warning = '' else: self.weather = tmod.open_json('weather.json', 'home') self.warning = 'NAPI Using Saved Data' except Exception as e: self.weather = tmod.open_json('weather.json', 'home') self.warning = 'ER Using Saved Data' logging.info('Collect weather error: ' + str(e)) pass self.units_of_measure()
def get_weather_info(self): self.read_config() location = self.geolocation(self.code) lat, long, self.city = location print(" This is the location {}".format(location)) try: if self.api == True: f = requests.get( 'https://api.darksky.net/forecast/{}/{},{}'.format( key, lat, long)) weather = f.json() tmod.save_json('weather.json', weather, 'home') self.weather = tmod.open_json('weather.json', 'home') self.warning = '' else: self.weather = tmod.open_json('weather.json', 'home') self.warning = 'NAPI Using Saved Data' except Exception as e: self.weather = tmod.open_json('weather.json', 'home') self.warning = 'ER Using Saved Data' logging.info('Collect weather error: ' + str(e)) pass self.units_of_measure()
def read_config(self,file_='config.json'): config = tm.open_json(file_) config_value = [value for (key,value) in sorted(config.items())] self.broker_add = config_value[1]