Exemplo n.º 1
0
    def _parse_title(self, line, comment, conversation):
        m = self.TITLE_LINE_RE.match(line)
        info = util.parse_string(m.group('titlestr'), self.TITLE_PATTERN)
        self._parse_info(info, conversation)
        original_parser_name = comment.split('/')[1] if comment else self.type

        return info, original_parser_name
Exemplo n.º 2
0
    def parse_path(self, path):
        info = util.parse_string(path, self.FILE_PATTERN, path=True)
        if not info:
            return None

        time = self._parse_time(info['time'], self.STRPTIME_FMT_FILE)
        destination = info['destination']
        service = self.SERVICE_MAP[info['service']]
        source = info['source']

        with codecs.open(path, encoding='utf-8') as f:
            data = f.read().strip()
            lines = data.split('\n')
        isgroup = self._isgroup(lines, path, source, destination)

        dp = join(dirname(path), self.IMAGE_DIRECTORY)
        images = [relpath(join(dp, x), start=dp) for x in os.listdir(dp)
                  if not x.endswith('.xml')]

        # create conversation with tranformed source
        conversation = Conversation(self, path, source, destination,
                                    service, time, entries=[], images=images,
                                    isgroup=isgroup,
                                    transforms=self.TRANSFORMS)
        conversation.lines = lines

        return [conversation]
Exemplo n.º 3
0
    def _parse_status(self, comment, info, conversation):
        if comment:
            info['type'], info['system'], info['sender'] = \
                comment.split("|", 2)
            info['type'] = int(info['type'])
            if info['type'] in Status.USER_TYPES:
                l = info['html'][0].split(': ', 1)
                if len(l) == 2:
                    info['msg_html'] = [NavigableString(l[1])]+info['html'][1:]

                info['html'] = []
            return

        s = ''.join([x.text if isinstance(x, Tag) else x.string
                     for x in info['html']])
        info['sender'] = conversation.source \
            if s.startswith(_("You")) else None

        if not info['type']:
            typemap = dict(self.STATUS_TYPEMAP, **self.CHAT_STATUS_TYPEMAP) if \
                conversation.isgroup else self.STATUS_TYPEMAP
            for pattern, t in iter(typemap.items()):
                i = util.parse_string(s, pattern)
                if i is not None:
                    for k, v in iter(i.items()):
                        info[k] = v
                    # special case for 'is no longer <type>'
                    typestr = i.get('type')
                    if typestr:
                        info['type'] = \
                            Status.OPPOSITES[Status.PAM_EPYT[typestr]]
                    else:
                        info['type'] = t
                    break
Exemplo n.º 4
0
    def _parse_title(self, line, comment, conversation):
        m = self.TITLE_LINE_RE.match(line)
        info = util.parse_string(m.group('titlestr'), self.TITLE_PATTERN)
        self._parse_info(info, conversation)
        original_parser_name = comment.split('/')[1] if comment else self.type

        return info, original_parser_name
Exemplo n.º 5
0
    def _parse_status(self, comment, info, conversation):
        if comment:
            info['type'], info['system'], info['sender'] = \
                comment.split("|", 2)
            info['type'] = int(info['type'])
            if info['type'] in Status.USER_TYPES:
                l = info['html'][0].split(': ', 1)
                if len(l) == 2:
                    info['msg_html'] = [NavigableString(l[1])
                                        ] + info['html'][1:]

                info['html'] = []
            return

        s = ''.join(
            [x.text if isinstance(x, Tag) else x.string for x in info['html']])
        info['sender'] = conversation.source \
            if s.startswith(_("You")) else None

        if not info['type']:
            typemap = dict(self.STATUS_TYPEMAP, **self.CHAT_STATUS_TYPEMAP) if \
                conversation.isgroup else self.STATUS_TYPEMAP
            for pattern, t in iter(typemap.items()):
                i = util.parse_string(s, pattern)
                if i is not None:
                    for k, v in iter(i.items()):
                        info[k] = v
                    # special case for 'is no longer <type>'
                    typestr = i.get('type')
                    if typestr:
                        info['type'] = \
                            Status.OPPOSITES[Status.PAM_EPYT[typestr]]
                    else:
                        info['type'] = t
                    break
Exemplo n.º 6
0
    def parse_path(self, path):
        info = util.parse_string(path, self.FILE_PATTERN, path=True)
        if not info:
            return None

        time = self._parse_time(info['time'], self.STRPTIME_FMT_FILE)
        destination = info['destination']
        service = self.SERVICE_MAP[info['service']]
        source = info['source']

        with codecs.open(path, encoding='utf-8') as f:
            data = f.read().strip()
            lines = data.split('\n')
        isgroup = self._isgroup(lines, path, source, destination)

        dp = join(dirname(path), self.IMAGE_DIRECTORY)
        images = [
            relpath(join(dp, x), start=dp) for x in os.listdir(dp)
            if not x.endswith('.xml')
        ]

        # create conversation with tranformed source
        conversation = Conversation(self,
                                    path,
                                    source,
                                    destination,
                                    service,
                                    time,
                                    entries=[],
                                    images=images,
                                    isgroup=isgroup,
                                    transforms=self.TRANSFORMS)
        conversation.lines = lines

        return [conversation]
Exemplo n.º 7
0
    def parse_path(self, path):
        info = util.parse_string(path, self.FILE_PATTERN, path=True)
        if not info:
            return None

        self._parse_info(info)
        if info['destination'] == '.system':
            print_d('Ignoring system log %s' % path)
            return None

        conversation = Conversation(self, path, info['source'],
                                    info['destination'],
                                    info['service'], info['time'],
                                    [], [], resource=info['resource'],
                                    isgroup=info['isgroup'])

        return [conversation]
Exemplo n.º 8
0
    def parse_path(self, path):
        info = util.parse_string(path, self.FILE_PATTERN, path=True)
        if not info:
            return None

        self._parse_info(info)
        if info['destination'] == '.system':
            print_d('Ignoring system log %s' % path)
            return None

        conversation = Conversation(self,
                                    path,
                                    info['source'],
                                    info['destination'],
                                    info['service'],
                                    info['time'], [], [],
                                    resource=info['resource'],
                                    isgroup=info['isgroup'])

        return [conversation]