예제 #1
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
예제 #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))