Ejemplo n.º 1
0
    def _parse_notes(self, node):
        note_files = node.Search(r'Note_\d+.txt')
        deleted_note_files = self.root.Search(r'NoteDeleted_\d+.txt')

        note_existing = 0
        note_deleted = 1

        files = [(f, note_existing)
                 for f in note_files] + [(f, note_deleted)
                                         for f in deleted_note_files]

        for f, is_deleted in files:
            data = self._open_file(f)
            for n in data.get('entries', []):
                try:
                    note = model_notes.Notes()
                    note.html_content = n.get('snippet', None)
                    note.deleted = is_deleted
                    note.source = f.AbsolutePath
                    note.fold_id = n.get('folderId', None)
                    note.id = n['id']
                    note.modified = TimeHelper.convert_timestamp(
                        n.get('modifyDate', None))
                    note.created = TimeHelper.convert_timestamp(
                        n.get('createDate', None))
                    self.nm.db_insert_table_notes(note)
                except Exception as e:
                    print(e)
        self.nm.db_commit()
Ejemplo n.º 2
0
 def _parse_photos(self, node):
     gallery_files = node.Search(r'Gallery_user_galleries_\d+.txt')
     for f in gallery_files:
         data = self._open_file(f)
         for g in data.get('galleries', []):
             try:
                 file_name = g.get('fileName', None)
                 if not file_name:
                     continue
                 pic = next(iter(self.root.Search(file_name)), None)
                 if not pic:
                     continue
                 m = model_media.Media()
                 m.source = f.AbsolutePath
                 m.url = pic.AbsolutePath
                 m.id = g.get('id', None)
                 m.title = g.get('title', None)
                 m.type = 'image'
                 m.modify_date = TimeHelper.convert_timestamp(
                     g.get('dateModified', None))
                 m.add_date = TimeHelper.str_to_ts(
                     g.get('exifinfo', {}).get('dateTime', None),
                     _format="%Y-%m-%d %H:%M:%S")
                 m.size = g.get('size', None)
                 m.height = g.get('exifinfo', {}).get('imageLength', None)
                 m.width = g.get('exifinfo', {}).get('imageWidth', None)
                 self.mm.db_insert_table_media(m)
             except Exception as e:
                 print(e)
     self.mm.db_commit()
Ejemplo n.º 3
0
    def _parse_sms(self, node):
        sms_files = node.Search(r'Sms_\d+.txt')
        for file_ in sms_files:
            data = self._open_file(file_)
            phone_calls = data.get('phonecall_view', {}).get('entries', [])
            sms = data.get('entries', [])

            for pc in phone_calls:
                try:
                    record = model_callrecord.Records()
                    record.source = file_.AbsolutePath
                    record.duration = pc.get('duration', None)
                    record.phone_number = pc.get('number', None)
                    record.id = pc.get('id', None)
                    record.date = TimeHelper.convert_timestamp(
                        pc.get('date', None))
                    self.crm.db_insert_table_call_records(record)
                except Exception as e:
                    print(e)

            for s in sms:
                try:
                    s = s['entry']
                    message = model_sms.SMS()
                    message.source = file_.AbsolutePath
                    message.body = s.get('snippet', None)
                    message.send_time = TimeHelper.convert_timestamp(
                        s.get('localTime', None))
                    message.read_status = 1 if s['unread'] == 0 else 0
                    message.is_sender = 1 if s['folder'] == 1 else 0
                    message._id = s.get('id', None)
                    recipients = s.get('recipients', None)
                    message.sender_phonenumber, message.recv_phonenumber = (self.owner_phone, recipients) \
                        if message.is_sender else (recipients, self.owner_phone)
                    self.sms.db_insert_table_sms(message)
                except Exception as e:
                    print(e)

        self.crm.db_commit()
        self.sms.db_commit()
Ejemplo n.º 4
0
    def _generate_account_table(self):
        """
        创建account table
        """
        msg_db_col = self.message_col
        account_id = os.path.basename(msg_db_col.db_path).split(".")[0]

        db_col = self.soul_app_col
        table = db_col.get_table(
            "user", {
                "_id": [FieldType.Int, FieldConstraints.NotNull],
                "user": [FieldType.Text, FieldConstraints.NotNull],
            })
        for rec in db_col.read_records(table):
            try:
                if str(rec['_id'].Value) == account_id:
                    account_info = TaoUtils.json_loads(rec['user'].Value)
                    if not account_info:
                        continue

                    account = model_im.Account()
                    account.account_id = rec['_id'].Value
                    account.source = db_col.db_path
                    account.signature = account.username = account.nickname = account_info.get(
                        "signature", None)
                    account.gender = model_im.GENDER_FEMALE if account_info.get("gender", None) == "FEMALE" \
                        else model_im.GENDER_MALE
                    account.birthday = TimeHelper.convert_timestamp(
                        account_info.get("birthday", None))
                    account.email = account_info.get('bindMail', None)
                    account.country = "China" if account_info.get(
                        'area', None) else None
                    account.deleted = 1 if rec.IsDeleted else 0
                else:
                    account = model_im.Account()
                    account.account_id = account.username = account.nickname = account_id
                    account.source = db_col.db_path
                self.model_im_col.db_insert_table_account(account)
            except Exception as e:
                self.logger.error()
        self.model_im_col.db_commit()
Ejemplo n.º 5
0
    def convert_message_content(self, content, msg_obj):
        content = content.strip()
        if not (content.startswith("<") and content.endswith(">")):
            return content
        try:
            hp = PaHtmlParser()
            hp.feed(content)
            hp.close()

            tag_name = hp.first_dom.tag_name
            if tag_name == "deletemember":
                executor = hp.root['deletemember']['initiator'].data
                target = hp.root['deletemember']['target'].data
                return self.assemble_message_delete_member(executor, target)
            elif tag_name == "addmember":
                executor = hp.root['addmember']['initiator'].data
                target = hp.root['addmember']['target'].data
                return self.assemble_message_add_member(executor, target)
            elif tag_name == "ss":
                nodes = hp.root.get_all("ss")
                return self.assemble_message_emoji(nodes)
            elif tag_name == "uriobject":
                if hp.root['uriobject'].get("swift", None):
                    encoded_info = hp.root['uriobject']['swift'].property[
                        'b64']
                    decoded_info = TaoUtils.decode_base64(encoded_info)
                    attachment = json.loads(decoded_info)["attachments"][0]
                    url = attachment["content"]['images'][0]['url']
                    return url
                return hp.root['uriobject']['originalname'].property['v']
            elif tag_name == 'partlist':
                return self.assemble_message_call(hp.root, msg_obj.account_id)
            elif tag_name == 'topicupdate':
                return self.assemble_message_rename_group(hp.root)
            elif tag_name == 'location':
                address = hp.root['location'].property['address']
                latitude = float(
                    hp.root['location'].property['latitude']) / 1000000
                longitude = float(
                    hp.root['location'].property['longitude']) / 1000000
                ts = TimeHelper.convert_timestamp(
                    hp.root['location'].property.get("timestamp", None))
                location = model_im.Location()
                location.account_id = self.using_account.account_id
                location.address = address
                location.latitude = latitude
                location.longitude = longitude
                location.timestamp = ts
                self.model_im_col.db_insert_table_location(location)
                msg_obj.location_id = location.location_id
                msg_obj.type = model_im.MESSAGE_CONTENT_TYPE_LOCATION
                return None
            elif tag_name == 'historydisclosedupdate':
                return self.assemble_message_history_closure(hp.root)
            elif tag_name == 'joiningenabledupdate':
                return self.assemble_message_close_add_memeber(hp.root)
            elif tag_name == "sms":
                return hp.root['sms']['defaults']['content'].data
            elif tag_name == "pictureupdate":
                return self.assemble_message_change_pic_bak(hp.root)
            else:
                return content
        except Exception as e:
            return content