How to use the meteomatics.binary_reader.BinaryReaderException function in meteomatics

To help you get started, we’ve selected a few meteomatics 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 meteomatics / python-connector-api / meteomatics / binary_reader.py View on Github external
def get(self, data_type, n=1):
        try:
            data_type = data_type.lower()
        except AttributeError:
            raise BinaryReaderException("Argument data_type has to be string")

        data = self._read_data(data_type, n)
        if n == 1:
            return data[0]
        else:
            return data
github meteomatics / python-connector-api / meteomatics / binary_reader.py View on Github external
def _read_data(self, data_type, n):
        try:
            num_of_bytes = self.DATA_TYPES[data_type]["num_of_bytes"]
        except KeyError as e:
            raise BinaryReaderException("Data type: '{}' is not valid. Valid types: [{}]".format(data_type,
                                                                                                 ", ".join(
                                                                                                     self.DATA_TYPES.keys())))

        substring = self._binary_data[self._pointer:self._pointer + num_of_bytes * n]

        if len(substring) != num_of_bytes * n:
            raise BinaryReaderException(
                "Not possible to read {} bytes, length of binary data is {} bytes".format(num_of_bytes * n,
                                                                                          len(self)))
        self._pointer += num_of_bytes * n
        return struct.unpack("<{}".format(self.DATA_TYPES[data_type]["format_char"] * n), substring)
github meteomatics / python-connector-api / meteomatics / binary_reader.py View on Github external
def __init__(self, message):
        super(BinaryReaderException, self).__init__(message)
github meteomatics / python-connector-api / meteomatics / binary_reader.py View on Github external
def _read_data(self, data_type, n):
        try:
            num_of_bytes = self.DATA_TYPES[data_type]["num_of_bytes"]
        except KeyError as e:
            raise BinaryReaderException("Data type: '{}' is not valid. Valid types: [{}]".format(data_type,
                                                                                                 ", ".join(
                                                                                                     self.DATA_TYPES.keys())))

        substring = self._binary_data[self._pointer:self._pointer + num_of_bytes * n]

        if len(substring) != num_of_bytes * n:
            raise BinaryReaderException(
                "Not possible to read {} bytes, length of binary data is {} bytes".format(num_of_bytes * n,
                                                                                          len(self)))
        self._pointer += num_of_bytes * n
        return struct.unpack("<{}".format(self.DATA_TYPES[data_type]["format_char"] * n), substring)