How to use the pyowm.commons.exceptions.ParseAPIResponseError function in pyowm

To help you get started, we’ve selected a few pyowm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csparpa / pyowm / tests / unit / airpollutionapi30 / test_no2index.py View on Github external
def test_test_from_dict_fails_when_JSON_data_is_None(self):
        self.assertRaises(ParseAPIResponseError, NO2Index.from_dict, None)
github csparpa / pyowm / tests / unit / airpollutionapi30 / test_so2index.py View on Github external
def test_parse_JSON_fails_with_malformed_JSON_data(self):
        self.assertRaises(ParseAPIResponseError, SO2Index.from_dict, json.loads(SO2INDEX_MALFORMED_JSON))
github csparpa / pyowm / tests / unit / airpollutionapi30 / test_ozone.py View on Github external
def test_from_dict_fails_when_JSON_data_is_None(self):
        self.assertRaises(pyowm.commons.exceptions.ParseAPIResponseError, Ozone.from_dict, None)
github csparpa / pyowm / tests / unit / airpollutionapi30 / test_ozone.py View on Github external
def test_from_dict_fails_with_malformed_JSON_data(self):
        self.assertRaises(pyowm.commons.exceptions.ParseAPIResponseError, Ozone.from_dict, json.loads(OZONE_MALFORMED_JSON))
github csparpa / pyowm / tests / unit / airpollutionapi30 / test_so2index.py View on Github external
def test_parse_JSON_fails_when_JSON_data_is_None(self):
        self.assertRaises(ParseAPIResponseError, SO2Index.from_dict, None)
github csparpa / pyowm / pyowm / airpollutionapi30 / ozone.py View on Github external
def from_dict(cls, the_dict):
        """
        Parses an *Ozone* instance out of a data dictionary. Only certain properties of the data dictionary
        are used: if these properties are not found or cannot be parsed, an exception is issued.

        :param the_dict: the input dictionary
        :type the_dict: `dict`
        :returns: an *Ozone* instance or ``None`` if no data is available
        :raises: *ParseAPIResponseError* if it is impossible to find or parse the data needed to build the result

        """
        if the_dict is None:
            raise exceptions.ParseAPIResponseError('Data is None')
        try:
            # -- reference time (strip away Z and T on ISO8601 format)
            ref_t = the_dict['time'].replace('Z', '+00').replace('T', ' ')
            reference_time = formatting.ISO8601_to_UNIXtime(ref_t)

            # -- reception time (now)
            reception_time = timestamps.now('unix')

            # -- location
            lon = float(the_dict['location']['longitude'])
            lat = float(the_dict['location']['latitude'])
            place = location.Location(None, lon, lat, None)

            # -- ozone Dobson Units value
            du = the_dict['data']
            if du is not None:
github csparpa / pyowm / pyowm / airpollutionapi30 / no2index.py View on Github external
# -- reception time (now)
            reception_time = timestamps.now('unix')

            # -- location
            lon = float(the_dict['location']['longitude'])
            lat = float(the_dict['location']['latitude'])
            place = location.Location(None, lon, lat, None)

            # -- CO samples
            no2_samples = [dict(label=key,
                                precision=the_dict['data'][key]['precision'],
                                value=the_dict['data'][key]['value']) for key in the_dict['data']]

        except KeyError:
            raise exceptions.ParseAPIResponseError(
                      ''.join([__name__, ': impossible to parse NO2Index']))

        return NO2Index(reference_time, place, None, no2_samples, reception_time)
github csparpa / pyowm / pyowm / airpollutionapi30 / coindex.py View on Github external
def from_dict(cls, the_dict):
        """
        Parses a *COIndex* instance out of a data dictionary. Only certain properties of the data dictionary
        are used: if these properties are not found or cannot be parsed, an exception is issued.

        :param the_dict: the input dictionary
        :type the_dict: `dict`
        :returns: a *COIndex* instance or ``None`` if no data is available
        :raises: *ParseAPIResponseError* if it is impossible to find or parse the data needed to build the result

        """
        if the_dict is None:
            raise exceptions.ParseAPIResponseError('Data is None')
        try:
            # -- reference time (strip away Z and T on ISO8601 format)
            t = the_dict['time'].replace('Z', '+00').replace('T', ' ')
            reference_time = formatting.ISO8601_to_UNIXtime(t)

            # -- reception time (now)
            reception_time = timestamps.now('unix')

            # -- location
            lon = float(the_dict['location']['longitude'])
            lat = float(the_dict['location']['latitude'])
            place = location.Location(None, lon, lat, None)

            # -- CO samples
            co_samples = the_dict['data']
github csparpa / pyowm / pyowm / stationsapi30 / measurement.py View on Github external
def from_dict(cls, the_dict):
        """
        Parses an *AggregatedMeasurement* instance out of a data dictionary. Only certain properties of the data dictionary
        are used: if these properties are not found or cannot be parsed, an exception is issued.

        :param the_dict: the input dictionary
        :type the_dict: `dict`
        :returns: an *AggregatedMeasurement* instance or ``None`` if no data is available
        :raises: *ParseAPIResponseError* if it is impossible to find or parse the data needed to build the result

        """
        if the_dict is None:
            raise exceptions.ParseAPIResponseError('Data is None')
        station_id = the_dict.get('station_id', None)
        ts = the_dict.get('date', None)
        if ts is not None:
            ts = int(ts)
        aggregated_on = the_dict.get('type', None)
        temp = the_dict.get('temp', dict())
        humidity = the_dict.get('humidity', dict())
        wind = the_dict.get('wind', dict())
        pressure = the_dict.get('pressure', dict())
        precipitation = the_dict.get('precipitation', dict())
        return AggregatedMeasurement(station_id, ts, aggregated_on, temp=temp, humidity=humidity, wind=wind,
                                     pressure=pressure, precipitation=precipitation)
github csparpa / pyowm / pyowm / airpollutionapi30 / so2index.py View on Github external
def from_dict(cls, the_dict):
        """
        Parses a *SO2Index* instance out of a data dictionary. Only certain properties of the data dictionary
        are used: if these properties are not found or cannot be parsed, an exception is issued.

        :param the_dict: the input dictionary
        :type the_dict: `dict`
        :returns: a *SO2Index* instance or ``None`` if no data is available
        :raises: *ParseAPIResponseError* if it is impossible to find or parse the data needed to build the result

        """
        if the_dict is None:
            raise exceptions.ParseAPIResponseError('Data is None')
        try:
            # -- reference time (strip away Z and T on ISO8601 format)
            t = the_dict['time'].replace('Z', '+00').replace('T', ' ')
            reference_time = formatting.ISO8601_to_UNIXtime(t)

            # -- reception time (now)
            reception_time = timestamps.now('unix')

            # -- location
            lon = float(the_dict['location']['longitude'])
            lat = float(the_dict['location']['latitude'])
            place = location.Location(None, lon, lat, None)

            # -- SO2 samples
            so2_samples = the_dict['data']