Пример #1
0
 def load_settings(main_table, raw_table, schemas):
     '''Process the categories in settings in a safe manner'''
     for category in schemas.keys():
         main_table[category] = []
         schema = schemas[category]
         if category in raw_table.keys():
             if isinstance(raw_table[category], list):
                 for entry in raw_table[category]:
                     final_entry = helpers.merge_dicts(schema, entry)
                     main_table[category].append(final_entry)
             else:
                 main_table[category].append(helpers.merge_dicts(schema, raw_table[category]))
Пример #2
0
    def add_history_entry(self, rtime: str, wtype: str, raw_data_map: Sequence[Dict[str, Union[str, dict]]]) -> None:
        entry = helpers.merge_dicts(self.entry_schema, {'time': rtime, 'wtype': wtype})
        for raw_entry in raw_data_map:
            data = raw_entry['data']
            location = raw_entry['location']
            source = raw_entry['source']
            try:
                measurements = adapters.adapt_weather(wtype, source['name'].lower(), data)
            except:
                measurements = {}
            history_entry = {'location': location, 'source': source, 'measurements': measurements}
            helpers.db_add(entry['data'], helpers.merge_dicts(self.data_entry_schema, history_entry))
        helpers.db_add(self.__table, entry)

        return json.loads(json.dumps(entry))
Пример #3
0
    def add_location(self, accuweather_city_name: str = '', gismeteo_city_name: str = '', country_name: str = '', longitude: str = '', gismeteo_id: str = '', iso_country: str = '', city_name: str = '', latitude: str = '', accuweather_id: str = ''):

        location = helpers.merge_dicts(LOCATION_ENTRY_SCHEMA, {'accuweather_city_name': accuweather_city_name, 'gismeteo_city_name': gismeteo_city_name, 'country_name': country_name, 'longitude': longitude, 'gismeteo_id': gismeteo_id, 'iso_country': iso_country, 'city_name': city_name, 'latitude': latitude, 'accuweather_id': accuweather_id})

        data = self.core.proxies.add_location(location, self.environment()['environment'])

        return helpers.output_data(data)
Пример #4
0
    def add_location(self, location: Dict[str, str], params: Dict[str, str]):
        output = []
        for category, source in itertools.product(self.wtypes, self.sources_info):
            url_params = {}
            url_params.update(location)
            url_params.update(params)
            entry = helpers.merge_dicts(self.proxy_entry_schema, {'proxy': WeatherProxy(url=source['urls'][category], url_params=url_params), 'wtype': category, 'source': source, 'location': location})
            helpers.db_add(self.__table, entry)
            output.append(self.single_proxy_info(entry))

        return output
Пример #5
0
    def __init__(self) -> None:
        module_path = os.path.dirname(__spec__.origin)
        settings_path = os.path.join(module_path, 'settings.toml')
        schemas = {'sources': SOURCE_ENTRY_SCHEMA, 'locations': LOCATION_ENTRY_SCHEMA}

        self.__table = {}

        raw_table = helpers.load_table(settings_path)

        self.load_settings(self.__table, raw_table, schemas)

        self.__table['env'] = helpers.merge_dicts(ENV_SETTINGS_SCHEMA, dict(os.environ))