@require(internet)<EOL><INDENT>def get_station_id(self):<DEDENT>
extra_opts = '<STR_LIT>' if not self.use_pws else '<STR_LIT>'<EOL>api_url = GEOLOOKUP_URL % (self.api_key,<EOL>extra_opts,<EOL>self.location_code)<EOL>response = self.api_request(api_url)<EOL>station_type = '<STR_LIT>' if self.use_pws else '<STR_LIT>'<EOL>try:<EOL><INDENT>stations = response['<STR_LIT:location>']['<STR_LIT>']<EOL>nearest = stations[station_type]['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT>except (KeyError, IndexError):<EOL><INDENT>raise Exception(<EOL>'<STR_LIT>' % self.location_code)<EOL><DEDENT>self.logger.error('<STR_LIT>', nearest)<EOL>if self.use_pws:<EOL><INDENT>nearest_pws = nearest.get('<STR_LIT:id>', '<STR_LIT>')<EOL>if not nearest_pws:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>self.station_id = '<STR_LIT>' % nearest_pws<EOL><DEDENT>else:<EOL><INDENT>nearest_airport = nearest.get('<STR_LIT>', '<STR_LIT>')<EOL>if not nearest_airport:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>self.station_id = '<STR_LIT>' % nearest_airport<EOL><DEDENT>
Use geolocation to get the station ID