cellyzer/io.py
def read_msg(file_path='', file_type='csv', hash=True, decode_read="", splitted_line=None):
    """
    Loads message records dataset and returns a message dataset object
    :param file_path: file path of the dataset
    :param file_type: csv,xlsx,json file types are accepted
    :param hash: hash user phone numbers for privacy
    :return: MessageDataset object
    """
    print("[x]  Reading Message Data...")

    if type(file_path) != str or type(file_type) != str or type(hash) != bool:
        raise TypeError
    elif type(splitted_line) != list and splitted_line is not None:
        raise TypeError
    else:
        if not (decode_read == ""):
            data_list = decode_read.getvalue().split('\r\n')
            fieldnames = data_list[0].split(',')
            msg_list = []
            for line in data_list[1:len(data_list) - 1]:
                splitted_line = line.split(',')
                msg = dict()
                i = 0
                for f in fieldnames:
                    if splitted_line[i] is not None:
                        msg[f] = splitted_line[i]
                    else:
                        msg[f] = ''
                    i += 1
                msg_list.append(msg)
            return create_msg_obj(msg_list, fieldnames, hash)

        try:
            if file_type.lower() == 'csv':
                with open(file_path, 'r') as csv_file:
                    reader = csv.DictReader(csv_file)

                    fieldnames = reader.fieldnames
                    messages_list = []
                    for val in reader:
                        message = dict()
                        for f in fieldnames:
                            message[f] = val[f]
                        messages_list.append(message)

                    return create_msg_obj(messages_list, fieldnames, hash)
            elif file_type.lower() == 'xls' or file_type.lower() == 'xlsx':
                return read_xls(file_path, hash)
            elif file_type.lower() == 'json':
                return read_json(file_path, hash)
            else:
                print('Invalid Format')
        except IOError:
            print("IO Error :", IOError)
            pass

    Loads message records dataset and returns a message dataset object
    :param file_path: file path of the dataset
    :param file_type: csv,xlsx,json file types are accepted
    :param hash: hash user phone numbers for privacy
    :return: MessageDataset object
    
Loads message records dataset and returns a message dataset object
Loads message records dataset and returns a message dataset object
def read_msg(file_path='', file_type='csv', hash=True, decode_read="", splitted_line=None):
    print("[x]  Reading Message Data...")
    if type(file_path) != str or type(file_type) != str or type(hash) != bool:
        raise TypeError
    elif type(splitted_line) != list and splitted_line is not None:
        raise TypeError
    else:
        if not (decode_read == ""):
            data_list = decode_read.getvalue().split('\r\n')
            fieldnames = data_list[0].split(',')
            msg_list = []
            for line in data_list[1:len(data_list) - 1]:
                splitted_line = line.split(',')
                msg = dict()
                i = 0
                for f in fieldnames:
                    if splitted_line[i] is not None:
                        msg[f] = splitted_line[i]
                    else:
                        msg[f] = ''
                    i += 1
                msg_list.append(msg)
            return create_msg_obj(msg_list, fieldnames, hash)
        try:
            if file_type.lower() == 'csv':
                with open(file_path, 'r') as csv_file:
                    reader = csv.DictReader(csv_file)
                    fieldnames = reader.fieldnames
                    messages_list = []
                    for val in reader:
                        message = dict()
                        for f in fieldnames:
                            message[f] = val[f]
                        messages_list.append(message)
                    return create_msg_obj(messages_list, fieldnames, hash)
            elif file_type.lower() == 'xls' or file_type.lower() == 'xlsx':
                return read_xls(file_path, hash)
            elif file_type.lower() == 'json':
                return read_json(file_path, hash)
            else:
                print('Invalid Format')
        except IOError:
            print("IO Error :", IOError)
            pass
def read_msg ( file_path = '' , file_type = 'csv' , hash = True , decode_read = "" , splitted_line = None ) : print ( "[x]  Reading Message Data..." ) if type ( file_path ) != str or type ( file_type ) != str or type ( hash ) != bool : raise TypeError elif type ( splitted_line ) != list and splitted_line is not None : raise TypeError else : if not ( decode_read == "" ) : data_list = decode_read . getvalue ( ) . split ( '\r\n' ) fieldnames = data_list [ 0 ] . split ( ',' ) msg_list = [ ] for line in data_list [ 1 : len ( data_list ) - 1 ] : splitted_line = line . split ( ',' ) msg = dict ( ) i = 0 for f in fieldnames : if splitted_line [ i ] is not None : msg [ f ] = splitted_line [ i ] else : msg [ f ] = '' i += 1 msg_list . append ( msg ) return create_msg_obj ( msg_list , fieldnames , hash ) try : if file_type . lower ( ) == 'csv' : with open ( file_path , 'r' ) as csv_file : reader = csv . DictReader ( csv_file ) fieldnames = reader . fieldnames messages_list = [ ] for val in reader : message = dict ( ) for f in fieldnames : message [ f ] = val [ f ] messages_list . append ( message ) return create_msg_obj ( messages_list , fieldnames , hash ) elif file_type . lower ( ) == 'xls' or file_type . lower ( ) == 'xlsx' : return read_xls ( file_path , hash ) elif file_type . lower ( ) == 'json' : return read_json ( file_path , hash ) else : print ( 'Invalid Format' ) except IOError : print ( "IO Error :" , IOError ) pass
Loads message records dataset and returns a message dataset object
Loads message records dataset and returns a message dataset object
"""
    Loads message records dataset and returns a message dataset object
    :param file_path: file path of the dataset
    :param file_type: csv,xlsx,json file types are accepted
    :param hash: hash user phone numbers for privacy
    :return: MessageDataset object
    """
None
file_path
file path of the dataset
file path of the dataset
file_type
csv,xlsx,json file types are accepted
csv xlsx json file types are accepted
hash
hash user phone numbers for privacy
hash user phone numbers for privacy
decode_read
splitted_line