Ejemplo n.º 1
0
    def _create_messages(self, names, data, isDms=False):
        """
        Creates object of arrays of messages from each json file specified by the names or ids

        :param [str] names: names of each group of messages

        :param [object] data: array of objects detailing where to get the messages from in
        the directory structure

        :param bool isDms: boolean value used to tell if the data is dm data so the function can
        collect the empty dm directories and store them in memory only

        :return: object of arrays of messages

        :rtype: object
        """

        chats = {}
        empty_dms = []

        for name in names:

            # gets path to dm directory that holds the json archive
            dir_path = os.path.join(self._PATH, name)
            messages = []
            # array of all days archived
            day_files = glob.glob(os.path.join(dir_path, "*.json"))

            # this is where it's skipping the empty directories
            if not day_files:
                if isDms:
                    empty_dms.append(name)
                continue

            for day in sorted(day_files):
                with io.open(os.path.join(self._PATH, day),
                             encoding="utf8") as f:
                    # loads all messages
                    # msgs = []
                    # for line in msgs:
                    #     msgs.append(json.loads(line))

                    # day_messages = msgs
                    try:
                        day_messages = json.load(f)
                    except ValueError:
                        day_messages = ''

                    messages.extend([
                        Message(self.__USER_DATA, data, d)
                        for d in day_messages
                    ])

            chats[name] = messages

        if isDms:
            self._EMPTY_DMS = empty_dms

        return chats
Ejemplo n.º 2
0
def compile_channels(path, user_data, channel_data):
    channels = get_channel_list(path)
    chats = {}
    for channel in channels:
        channel_dir_path = os.path.join(path, "channels")
        with open(os.path.join(channel_dir_path, channel + ".json")) as f:
            json_messages = json.load(f)
            messages = [
                Message(user_data, channel_data, d) for d in json_messages
            ]
        chats[channel] = messages[::-1]
    return chats
Ejemplo n.º 3
0
def compile_channels(path, user_data, channel_data):
    channels = get_channel_list(path)
    chats = {}
    for channel in channels:
        channel_dir_path = os.path.join(path, channel)
        messages = []
        for day in sorted(os.listdir(channel_dir_path)):
            with open(os.path.join(channel_dir_path, day)) as f:
                day_messages = json.load(f)
                messages.extend([
                    Message(user_data, channel_data, d) for d in day_messages
                ])
        chats[channel] = messages
    return chats
Ejemplo n.º 4
0
def compile_dms(path, user_data, dm_data):
    dms = get_dm_list(path)
    chats = {}
    for dm in dms:
        dm_dir_path = os.path.join(path, dm)
        messages = []
        day_files = glob.glob(os.path.join(dm_dir_path, "*.json"))
        if not day_files:
            continue
        for day in sorted(day_files):
            with io.open(os.path.join(path, day)) as f:
                day_messages = json.load(f)
                messages.extend(
                    [Message(user_data, dm_data, d) for d in day_messages])
        chats[dm] = messages
    return chats
Ejemplo n.º 5
0
def compile_groups(path, user_data, group_data):
    groups = get_group_list(path)
    chats = {}
    for group in groups:
        group_dir_path = os.path.join(path, group)
        messages = []
        day_files = glob.glob(os.path.join(group_dir_path, "*.json"))
        if not day_files:
            continue
        for day in sorted(day_files):
            with io.open(os.path.join(path, day)) as f:
                day_messages = json.load(f)
                messages.extend(
                    [Message(user_data, group_data, d) for d in day_messages])
        chats[group] = messages
    return chats
Ejemplo n.º 6
0
def compile_channels(path, user_data, channel_data):
    channels = get_channel_list(path)
    chats = {}
    for channel in channels:
        channel_dir_path = os.path.join(path, channel)
        messages = []
        day_files = glob.glob(os.path.join(channel_dir_path, "*.json"))
        if not day_files:
            continue
        for day in sorted(day_files):
            with open(os.path.join(path, day)) as f:
                day_messages = json.load(f)
                messages.extend([Message(user_data, channel_data, d) for d in
                                 day_messages])
        chats[channel] = messages
    return chats
Ejemplo n.º 7
0
def compile_channels(path, user_data, channel_data):
    channels = get_channel_list(path)
    chats = {}
    for channel in channels:
        c_id = [
            c for c in channel_data.keys()
            if channel_data[c]['name'] == channel
        ][0]
        channel_dir_path = os.path.join(path, channel)
        messages = []
        for day in sorted(os.listdir(channel_dir_path)):
            with open(os.path.join(channel_dir_path, day)) as f:
                day_messages = json.load(f)
                messages.extend([
                    Message(user_data, channel_data, d) for d in day_messages
                ])
        chats[channel] = {
            "messages": messages,
            "archived": channel_data[c_id]['is_archived']
        }
    return chats
Ejemplo n.º 8
0
    def _create_messages(self, type, channels, data):
        """
        Creates object of arrays of messages from each json file specified by the names or ids

        :param [str] channels: names of each group of messages

        :param [object] data: array of objects detailing where to get the messages from in
        the directory structure

        :param bool isDms: boolean value used to tell if the data is dm data so the function can
        collect the empty dm directories and store them in memory only

        :return: object of arrays of messages

        :rtype: object
        """

        dir = self._DIRS[type]
        chats = {}
        empty_dms = []

        for channel in channels:
            messages = []

            with io.open(os.path.join(
                    self._PATH, dir,
                    channel + '.json')) as f:  #, encoding="utf8") as f:
                # loads all messages
                channel_messages = json.load(f)
                messages.extend([
                    Message(self.__USER_DATA, data, type, channel, d)
                    for d in channel_messages['messages']
                ])

            chats[channel] = messages

        if type == 'dm':
            self._EMPTY_DMS = empty_dms

        return chats