import collections


def parse_candump_line(inputstring):
    """Parse a line from a candump log.

    The input should be a string, for example
    '(1459760909.868244) vcan0 008#9D0F000000000000\n'

    Returns a 'datapoint' object with the attributes:
        * timestamp (float)
        * interface (str)
        * can_id (int)
        * data (str)

    """
    timestamp_string = inputstring.split()[0].strip('()')
    timestamp = float(timestamp_string)

    id_data_string = inputstring.split()[2].strip()
    id_data_splitted = id_data_string.split('#')
    can_id = int(id_data_splitted[0], 16)
    data = id_data_splitted[1]

    interface = inputstring.split()[1].strip()

    Candump_datapoint = collections.namedtuple('Candump_datapoint', 'timestamp interface canid data')
    datapoint = Candump_datapoint(timestamp, interface, can_id, data)

    return datapoint