def set_geodata(self, data): """Apply geodata to internal attributes.""" self.city, state, self.countrycode, tz = data self.provincestate = get_state(self.countrycode, state) self.countryname = get_country(self.countrycode) self.timezone = tz.strip() return self.timezone
def load_results(self, entry, append, searched=set()): """Load a few search results based on what's been typed. Requires at least three letters typed, and is careful not to load duplicate results. The searched argument persists across calls to this method, and should not be passed as an argument unless your intention is to trigger the loading of duplicate results. """ text = entry.get_text().lower() three = text[0:3] self.search, search = [ re_compile('(^|\s)' + string, flags=IGNORECASE).search for string in (text, three) ] if len(three) == 3 and three not in searched: searched.add(three) with open(join(PKG_DATA_DIR, 'cities.txt')) as cities: for line in cities: city, lat, lon, country, state = line.split('\t')[0:5] if search(city): append([format_list([city, get_state(country, state), get_country(country)]), float(lat), float(lon)])
def load_results(self, entry, append, searched=set()): """Load a few search results based on what's been typed. Requires at least three letters typed, and is careful not to load duplicate results. The searched argument persists across calls to this method, and should not be passed as an argument unless your intention is to trigger the loading of duplicate results. """ text = entry.get_text().lower() three = text[0:3] self.search, search = [ re_compile('(^|\s)' + string, flags=IGNORECASE).search for string in (text, three) ] if len(three) == 3 and three not in searched: searched.add(three) with open(join(PKG_DATA_DIR, 'cities.txt')) as cities: for line in cities: city, lat, lon, country, state = line.split('\t')[0:5] if search(city): append([ format_list([ city, get_state(country, state), get_country(country) ]), float(lat), float(lon) ])
def set_geodata(self, data): """Override Coordinates.set_geodata to apply directly into IPTC.""" city, state, country, tz = data self.exif[IPTC + 'City'] = [city or ''] self.exif[IPTC + 'ProvinceState'] = [get_state(country, state) or ''] self.exif[IPTC + 'CountryName'] = [get_country(country) or ''] self.exif[IPTC + 'CountryCode'] = [country or ''] self.timezone = tz.strip()
def load_results(self, entry, append, searched=set()): """Load a few search results based on what's been typed. Requires at least three letters typed, and is careful not to load duplicate results. The searched argument persists across calls to this method, and should not be passed as an argument unless your intention is to trigger the loading of duplicate results. """ self.search = entry.get_text().lower() three = self.search[0:3] if len(three) == 3 and three not in searched: searched.add(three) with open(join(PKG_DATA_DIR, 'cities.txt')) as cities: for line in cities: city, lat, lon, country, state = line.split('\t')[0:5] if city.lower().find(three) > -1: append(( ', '.join([s for s in (city, get_state(country, state), get_country(country)) if s]), float(lat), float(lon)))
def lookup_geodata(self): """Check the cache for geonames, and notify of any changes. >>> coord = Coordinates() >>> coord.lookup_geodata() >>> coord.latitude = 47.56494 >>> coord.longitude = -52.70931 >>> coord.lookup_geodata() 'America/St_Johns' >>> coord.geoname "St. John's, Newfoundland and Labrador, Canada" """ if not self.positioned: return old_geoname = self.geoname city, state, code, tz = do_cached_lookup( GeoCacheKey(self.latitude, self.longitude)) self.names = (city, get_state(code, state), get_country(code)) self.geotimezone = tz.strip() if self.geoname != old_geoname: self.notify('geoname') return self.geotimezone