Beispiel #1
0
    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)
            cityfile = join(PKG_DATA_DIR, 'cities.txt')
            with open(cityfile, encoding='utf-8') 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)))
Beispiel #2
0
    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)
            cityfile = join(PKG_DATA_DIR, 'cities.txt')
            with open(cityfile, encoding='utf-8') 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)))
Beispiel #3
0
    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
    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