Example #1
0
def _migrate_settings():
    if 'units' in settings:
        if settings['units'] == 'US':
            settings['units'] = 'us'
        else:
            settings['units'] = 'si'

    if 'key' in settings:
        settings['key.wund'] = settings['key']
        del settings['key']

    settings['service'] = 'wund'

    if 'name' in settings:
        location = glocation.geocode(settings['name'])
        name = location['name']
        short_name = name.partition(',')[0] if ',' in name else name
        settings['location'] = {
            'name': name,
            'short_name': short_name,
            'latitude': location['latitude'],
            'longitude': location['longitude']
        }
        del settings['name']

    if 'timezone' not in settings['location']:
        location = settings['location']
        tz = glocation.timezone(location['latitude'], location['longitude'])
        settings['location']['timezone'] = tz['timeZoneId']

    settings['version'] = SETTINGS_VERSION
Example #2
0
    def _migrate_settings(self):
        if 'units' in self.config:
            if self.config['units'] == 'US':
                self.config['units'] = 'us'
            else:
                self.config['units'] = 'si'

        if 'key' in self.config:
            self.config['key.wund'] = self.config['key']
            del self.config['key']

        self.config['service'] = 'wund'

        if 'name' in self.config:
            location = glocation.geocode(self.config['name'])
            name = location['name']
            short_name = name.partition(',')[0] if ',' in name else name
            self.config['location'] = {
                'name': name,
                'short_name': short_name,
                'latitude': location['latitude'],
                'longitude': location['longitude']
            }
            del self.config['name']

        if 'timezone' not in self.config['location']:
            location = self.config['location']
            tz = glocation.timezone(location['latitude'],
                                    location['longitude'])
            self.config['location']['timezone'] = tz['timeZoneId']
Example #3
0
def _update_location(query):
    '''Temporarily update the location to a new value'''
    location = glocation.geocode(query)
    name = location['name']
    short_name = name.partition(',')[0] if ',' in name else name
    tz = glocation.timezone(location['latitude'], location['longitude'])
    temp_loc = {
        'name': name,
        'short_name': short_name,
        'latitude': location['latitude'],
        'longitude': location['longitude'],
        'timezone': tz['timeZoneId']
    }
    settings['location'].update(temp_loc)
Example #4
0
 def _update_location(self, query):
     '''Temporarily update the location to a new value'''
     location = glocation.geocode(query)
     name = location['name']
     short_name = name.partition(',')[0] if ',' in name else name
     tz = glocation.timezone(location['latitude'], location['longitude'])
     temp_loc = {
         'name': name,
         'short_name': short_name,
         'latitude': location['latitude'],
         'longitude': location['longitude'],
         'timezone': tz['timeZoneId']
     }
     self.config['location'].update(temp_loc)
Example #5
0
    def do_location(self, name):
        location_data = glocation.geocode(name)

        short_name = name
        if re.match('\d+ - .*', name):
            short_name = name.partition(' - ')[2]
        if ',' in short_name:
            short_name = short_name.split(',')[0]

        tz = glocation.timezone(location_data['latitude'],
                                location_data['longitude'])

        location = {
            'name': name,
            'short_name': short_name,
            'latitude': location_data['latitude'],
            'longitude': location_data['longitude'],
            'timezone': tz['timeZoneId']
        }

        self.config['location'] = location
        self.puts(u'Using location {}'.format(name))
Example #6
0
    def do_location(self, name):
        location_data = glocation.geocode(name)

        short_name = name
        if re.match('\d+ - .*', name):
            short_name = name.partition(' - ')[2]
        if ',' in short_name:
            short_name = short_name.split(',')[0]

        tz = glocation.timezone(location_data['latitude'],
                                location_data['longitude'])

        location = {
            'name': name,
            'short_name': short_name,
            'latitude': location_data['latitude'],
            'longitude': location_data['longitude'],
            'timezone': tz['timeZoneId']
        }

        self.config['location'] = location
        self.puts(u'Using location {}'.format(name))
Example #7
0
def do_location(name):
    location_data = glocation.geocode(name)

    short_name = name
    if re.match('\d+ - .*', name):
        short_name = name.partition(' - ')[2]
    if ',' in short_name:
        short_name = short_name.split(',')[0]

    tz = glocation.timezone(location_data['latitude'],
                            location_data['longitude'])

    location = {
        'name': name,
        'short_name': short_name,
        'latitude': location_data['latitude'],
        'longitude': location_data['longitude'],
        'timezone': tz['timeZoneId']
    }

    _load_settings(False)
    settings['location'] = location
    _save_settings()
    _out(u'Using location {}'.format(name))
Example #8
0
def do_location(name):
    location_data = glocation.geocode(name)

    short_name = name
    if re.match('\d+ - .*', name):
        short_name = name.partition(' - ')[2]
    if ',' in short_name:
        short_name = short_name.split(',')[0]

    tz = glocation.timezone(location_data['latitude'],
                            location_data['longitude'])

    location = {
        'name': name,
        'short_name': short_name,
        'latitude': location_data['latitude'],
        'longitude': location_data['longitude'],
        'timezone': tz['timeZoneId']
    }

    _load_settings(False)
    settings['location'] = location
    _save_settings()
    _out(u'Using location {}'.format(name))