@require(internet)<EOL><INDENT>def check_weather(self):<DEDENT>
if self.station_id is None:<EOL><INDENT>self.get_station_id()<EOL><DEDENT>self.data['<STR_LIT>'] = '<STR_LIT>'<EOL>try:<EOL><INDENT>query_url = STATION_QUERY_URL % (self.api_key,<EOL>'<STR_LIT>',<EOL>self.station_id)<EOL>try:<EOL><INDENT>response = self.api_request(query_url)['<STR_LIT>']<EOL>self.forecast_url = response.pop('<STR_LIT>', None)<EOL><DEDENT>except KeyError:<EOL><INDENT>self.logger.error('<STR_LIT>', self.station_id)<EOL>self.data['<STR_LIT>'] = self.update_error<EOL>return<EOL><DEDENT>if self.forecast:<EOL><INDENT>query_url = STATION_QUERY_URL % (self.api_key,<EOL>'<STR_LIT>',<EOL>self.station_id)<EOL>try:<EOL><INDENT>forecast = self.api_request(query_url)['<STR_LIT>']<EOL>forecast = forecast['<STR_LIT>']['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>except (KeyError, IndexError, TypeError):<EOL><INDENT>self.logger.error(<EOL>'<STR_LIT>', self.station_id)<EOL>self.data['<STR_LIT>'] = self.update_error<EOL><DEDENT>unit = '<STR_LIT>' if self.units == '<STR_LIT>' else '<STR_LIT>'<EOL>low_temp = forecast.get('<STR_LIT>', {}).get(unit, '<STR_LIT>')<EOL>high_temp = forecast.get('<STR_LIT>', {}).get(unit, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>low_temp = high_temp = '<STR_LIT>'<EOL><DEDENT>if self.units == '<STR_LIT>':<EOL><INDENT>temp_unit = '<STR_LIT:c>'<EOL>speed_unit = '<STR_LIT>'<EOL>distance_unit = '<STR_LIT>'<EOL>pressure_unit = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>temp_unit = '<STR_LIT:f>'<EOL>speed_unit = '<STR_LIT>'<EOL>distance_unit = '<STR_LIT>'<EOL>pressure_unit = '<STR_LIT>'<EOL><DEDENT>def _find(key, data=None, default='<STR_LIT>'):<EOL><INDENT>if data is None:<EOL><INDENT>data = response<EOL><DEDENT>return str(data.get(key, default))<EOL><DEDENT>try:<EOL><INDENT>observation_epoch = _find('<STR_LIT>') or _find('<STR_LIT>')<EOL>observation_time = datetime.fromtimestamp(int(observation_epoch))<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>log.debug(<EOL>'<STR_LIT>',<EOL>observation_epoch<EOL>)<EOL>observation_time = datetime.fromtimestamp(<NUM_LIT:0>)<EOL><DEDENT>self.data['<STR_LIT>'] = _find('<STR_LIT>', response['<STR_LIT>'])<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>')<EOL>self.data['<STR_LIT>'] = observation_time<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + temp_unit).split('<STR_LIT:.>')[<NUM_LIT:0>]<EOL>self.data['<STR_LIT>'] = low_temp<EOL>self.data['<STR_LIT>'] = high_temp<EOL>self.data['<STR_LIT>'] = '<STR_LIT>' + temp_unit.upper()<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + temp_unit)<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + temp_unit)<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + speed_unit)<EOL>self.data['<STR_LIT>'] = speed_unit<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>')<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + speed_unit)<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + pressure_unit)<EOL>self.data['<STR_LIT>'] = pressure_unit<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>')<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>' + distance_unit)<EOL>self.data['<STR_LIT>'] = distance_unit<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>').rstrip('<STR_LIT:%>')<EOL>self.data['<STR_LIT>'] = _find('<STR_LIT>')<EOL><DEDENT>except Exception:<EOL><INDENT>self.logger.error(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', exc_info=True<EOL>)<EOL>self.data['<STR_LIT>'] = self.update_error<EOL><DEDENT>
Query the configured/queried station and return the weather data