Esempio n. 1
0
def append_html(data, html, depth):
    tbody = html.tbody
    previous_filename = ''
    extract_images_list = list()
    new_file_path = NEW_FILE_PATH
    for datum in data:
        profile_tag = html.new_tag('td')
        profile_tag.string = datum['profile']
        location_tag = html.new_tag('td')
        location_tag.string = datum['location']
        datetime_tag = html.new_tag('td')
        datetime_tag.string = datum['datetime']

        image_tag = html.new_tag('td')
        # Get file name
        filename = utils.get_filename_from_url(datum['url'])
        # Get file type
        filetype = utils.get_filetype(datum['url'])
        if (depth == "fast"):
            # Create button
            button_tag = html.new_tag('button')
            button_tag['id'] = filename + filetype
            button_tag['class'] = 'btn_download_images_file btn btn-outline-dark my-2 my-sm-0'
            button_tag['value'] = datum['url']
            button_tag.append('Download Image')
            image_tag.append(button_tag)
        elif (depth == "complete"):
            url = datum['url']
            image = [new_file_path, url, filename, filetype]
            extract_images_list.append(image)
            # Show on html
            img_tag = html.new_tag('img')
            img_tag['src'] = f'images\{filename}{filetype}'
            image_tag.append(img_tag)
            previous_filename = filename

        row_tag = html.new_tag('tr')
        row_tag.append(profile_tag)
        row_tag.append(location_tag)
        row_tag.append(datetime_tag)
        row_tag.append(image_tag)
        tbody.append(row_tag)
    if (depth == "complete"):
        extract_image(extract_images_list)
Esempio n. 2
0
def build_conversations_profile_pic(html, participant_pic,
                                    participant_contact_id,
                                    participant_large_pic, div_col_left, depth,
                                    td_photo):
    filetype = utils.get_filetype(participant_pic)
    if (depth == "fast"):
        button_tag = html.new_tag('button')
        button_tag['id'] = str(participant_contact_id) + filetype
        button_tag[
            'class'] = 'btn_download_conversation_contact_image btn btn-outline-dark my-2 my-sm-0 fast-button pb-2'
        button_tag['value'] = participant_large_pic
        button_tag.append('Download Image')
        td_photo.append(button_tag)
    elif (depth == "complete"):
        href_tag = html.new_tag('a')
        href_tag[
            'href'] = f'conversations\images\large\{participant_contact_id}' + filetype
        img_tag = html.new_tag('img')
        img_tag[
            'src'] = f'conversations\images\small\{participant_contact_id}' + filetype
        img_tag['id'] = 'imgParticipant'
        href_tag.append(img_tag)
        td_photo.append(href_tag)
    return td_photo
Esempio n. 3
0
def fill_report_header(html, input_file_path, suspect_id, depth):

    SUSPECT_QUERRY = """
        SELECT
            profile_picture_url,
            name,
            profile_picture_large_url 
        FROM contacts
        WHERE id = """ + str(suspect_id)

    db_path = utils.get_suspect_db_path(input_file_path, suspect_id)

    # Connect to database
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    c.execute(SUSPECT_QUERRY)

    for row in c:
        small_pic = str(row[0])
        name = str(row[1])
        large_pic = str(row[2])

    div_container_fluid = html.new_tag("div")
    div_container_fluid["class"] = "container-fluid"
    div_container_row = html.new_tag("div")
    div_container_row["class"] = "row"

    # LOGO
    div_logo = html.new_tag("div")
    div_logo["class"] = "col-xl-1 mt-2"
    href_tag = html.new_tag("a")
    href_tag['href'] = '../index.html'
    img_logo = html.new_tag("img")
    img_logo["id"] = "imgLogo"
    img_logo["src"] = "../images/logo.png"
    img_logo["title"] = "Go back to index page"
    img_logo["alt"] = "Go back to index page"
    href_tag.append(img_logo)
    div_logo.append(href_tag)

    # HASH
    filename = db_path
    hashsum = sha256sum(db_path)
    timezone = datetime.timezone.utc
    timestamp = datetime.datetime.now(timezone).ctime()

    left_style_tag = "p"
    right_style_tag = "p"

    file_title = "File"
    hash_title = "Hash (SHA256)"
    datetime_title = "Time (UTC)"

    div_hash = html.new_tag("div")
    div_hash["class"] = "col-xl-8 text-center mt-3"
    div_hash_row_1 = html.new_tag("div")
    div_hash_row_1["class"] = "row"
    div_hash_row_1_col_left = html.new_tag("div")
    div_hash_row_1_col_left["class"] = "col text-right"
    div_hash_row_1_col_right = html.new_tag("div")
    div_hash_row_1_col_right["class"] = "col text-left"
    file_tag = html.new_tag(left_style_tag)
    file_tag.append(file_title)
    small_file_tag = html.new_tag("small")
    small_file_tag.append(file_tag)
    div_hash_row_1_col_left.append(small_file_tag)
    filename_tag = html.new_tag(right_style_tag)
    filename_tag.append(filename)
    small_filename = html.new_tag("small")
    small_filename.append(filename_tag)
    div_hash_row_1_col_right.append(small_filename)
    div_hash_row_1.append(div_hash_row_1_col_left)
    div_hash_row_1.append(div_hash_row_1_col_right)

    div_hash_row_2 = html.new_tag("div")
    div_hash_row_2["class"] = "row"
    div_hash_row_2_col_left = html.new_tag("div")
    div_hash_row_2_col_left["class"] = "col text-right"
    div_hash_row_2_col_right = html.new_tag("div")
    div_hash_row_2_col_right["class"] = "col text-left"
    sha_tag = html.new_tag(left_style_tag)
    sha_tag.append(hash_title)
    small_sha_tag = html.new_tag("small")
    small_sha_tag.append(sha_tag)
    div_hash_row_2_col_left.append(small_sha_tag)
    shaname_tag = html.new_tag(right_style_tag)
    shaname_tag.append(hashsum)
    small_shaname = html.new_tag("small")
    small_shaname.append(shaname_tag)
    div_hash_row_2_col_right.append(small_shaname)
    div_hash_row_2.append(div_hash_row_2_col_left)
    div_hash_row_2.append(div_hash_row_2_col_right)

    div_hash_row_3 = html.new_tag("div")
    div_hash_row_3["class"] = "row"
    div_hash_row_3_col_left = html.new_tag("div")
    div_hash_row_3_col_left["class"] = "col text-right"
    div_hash_row_3_col_right = html.new_tag("div")
    div_hash_row_3_col_right["class"] = "col text-left"
    timestamp_tag = html.new_tag(left_style_tag)
    timestamp_tag.append(datetime_title)
    small_timestamp_tag = html.new_tag("small")
    small_timestamp_tag.append(timestamp_tag)
    div_hash_row_3_col_left.append(small_timestamp_tag)
    timestamp_name_tag = html.new_tag(right_style_tag)
    timestamp_name_tag.append(str(timestamp))
    small_timestamp_name = html.new_tag("small")
    small_timestamp_name.append(timestamp_name_tag)
    div_hash_row_3_col_right.append(small_timestamp_name)
    div_hash_row_3.append(div_hash_row_3_col_left)
    div_hash_row_3.append(div_hash_row_3_col_right)

    div_hash.append(div_hash_row_1)
    div_hash.append(div_hash_row_2)
    div_hash.append(div_hash_row_3)

    # SUSPECT
    div_suspect = html.new_tag("div")
    div_suspect["class"] = "col-xl-3"
    div_suspect_row = html.new_tag("div")
    div_suspect_row["class"] = "row mt-4"
    div_suspect_col_name = html.new_tag("div")
    div_suspect_col_name["class"] = "col mt-3 ml-2 text-right"
    name_tag = html.new_tag("h5")
    name_tag["name"] = "suspect"
    name_tag.append(name)
    div_suspect_col_name.append(name_tag)
    div_suspect_col_img = html.new_tag("div")
    div_suspect_col_img["class"] = "col mt-2 pr-3"

    filetype = utils.get_filetype(small_pic)
    if (depth == "fast"):
        button_tag = html.new_tag('button')
        button_tag['id'] = str(suspect_id) + filetype
        button_tag['class'] = 'btn_download_conversation_contact_image btn btn-outline-dark my-2 my-sm-0'
        button_tag['value'] = large_pic
        button_tag.append('Download Image')
        div_suspect_col_img.append(button_tag)
    elif (depth == "complete"):
        href_tag = html.new_tag('a')
        href_tag['href'] = f'contacts\images\large\{suspect_id}' + filetype
        img_tag = html.new_tag('img')
        img_tag['src'] = f'contacts\images\small\{suspect_id}' + filetype
        img_tag['id'] = 'imgSuspect'
        href_tag.append(img_tag)
        div_suspect_col_img.append(href_tag)

    div_suspect_row.append(div_suspect_col_name)
    div_suspect_row.append(div_suspect_col_img)
    div_suspect.append(div_suspect_row)

    div_container_row.append(div_logo)
    div_container_row.append(div_hash)
    div_container_row.append(div_suspect)

    div_container_fluid.append(div_container_row)

    html.header.append(div_container_fluid)

    return html
Esempio n. 4
0
def header(html, thread_key, depth):

    one_participant_querry = """
        SELECT
            c.profile_picture_url,
            c.name,
            c.profile_picture_large_url, 
            p.thread_key,
            p.contact_id,
            p.nickname
        FROM participants as p 
        JOIN contacts as c ON c.id = p.contact_id
        WHERE p.thread_key = """ + str(thread_key)

    # Connect to database
    db_path = DB_PATH
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    c.execute(one_participant_querry)

    victim_photo = html.header.find("div", attrs={"id": "victimPhoto"})
    victim_name = html.header.find("div", attrs={"id": "victimName"})

    div_row_photo = html.new_tag('div')
    div_row_photo["class"] = "row"

    div_row_name = html.new_tag('div')
    div_row_name["class"] = "row"

    suspect_id = SUSPECT_ID

    for row in c:
        pic_url = str(row[0])
        name = str(row[1])
        large_pic_url = str(row[2])
        contact_id = str(row[4])

        if contact_id != suspect_id:
            filetype = utils.get_filetype(pic_url)
            div_col_photo = html.new_tag('div')
            div_col_photo["class"] = "col"
            if (depth == "fast"):
                button_tag = html.new_tag('button')
                button_tag['id'] = str(contact_id) + filetype
                button_tag[
                    'class'] = 'btn_download_conversation_contact_image btn btn-outline-dark my-2 my-sm-0 mt-2'
                button_tag['value'] = large_pic_url
                button_tag.append('Download Image')
                div_col_photo.append(button_tag)
            elif (depth == "complete"):
                href_tag = html.new_tag('a')
                href_tag[
                    'href'] = f'..\conversations\images\large\{contact_id}' + filetype
                img_tag = html.new_tag('img')
                img_tag[
                    'src'] = f'..\conversations\images\small\{contact_id}' + filetype
                img_tag['id'] = 'imgContact'
                href_tag.append(img_tag)
                div_col_photo.append(href_tag)

            div_row_photo.append(div_col_photo)

            # Fill name
            p_tag = html.new_tag('p')
            p_tag["class"] = "col"
            p_tag.append(name)

            div_row_name.append(p_tag)

    victim_photo.append(div_row_photo)
    victim_name.append(div_row_name)

    return html
Esempio n. 5
0
def report_html_conversations(template_path, depth):
    # Connect to database
    db_path = DB_PATH
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    c.execute(CONVERSATIONS_QUERRY)
    results = c.fetchall()
    results_lenght = len(results)

    # Get template
    template_file = open(template_path, 'r', encoding='utf-8')
    html_doc_new_file = BeautifulSoup(template_file, features='html.parser')
    new_file = open(NEW_FILE_PATH + "conversations.html",
                    'w',
                    encoding='utf-8')

    # Variable initialization
    thread_key = 0
    suspect_contact_id = SUSPECT_ID

    div_container_fluid = html_doc_new_file.new_tag('div')
    div_container_fluid["id"] = "divConversations"
    div_container_fluid["class"] = "container-fluid"

    extract_conversation_list = list()
    for i, row in enumerate(results):
        # Query fields
        participant_pic = str(row[0])
        participant_name = str(row[1])
        participant_large_pic = str(row[2])
        new_thread_key = row[3]
        participant_contact_id = row[4]
        participant_nickname = str(row[5])

        # # If is a new conversation..
        if thread_key != new_thread_key:
            div_conversation_group = html_doc_new_file.new_tag('div')
            div_conversation_group[
                "class"] = "container-fluid conversation-group"
            thread_key = new_thread_key
            build_conversations_div_row(html_doc_new_file,
                                        div_conversation_group, thread_key)

        # Div skeleton
        div_row_col = html_doc_new_file.new_tag('div')
        div_row_col["class"] = "row mt-2"
        div_col_left = html_doc_new_file.new_tag('div')
        div_col_left["class"] = "col text-right"
        div_col_right = html_doc_new_file.new_tag('div')
        div_col_right["class"] = "col text-left mt-3"

        # Table will not be visible, but its needed for csv export
        # td 1 - Profile Pic
        if (depth == "complete"):
            filetype = utils.get_filetype(participant_pic)
            conversation = [
                NEW_FILE_PATH, participant_pic, participant_large_pic,
                filetype,
                str(participant_contact_id)
            ]
            extract_conversation_list.append(conversation)
        td_photo = html_doc_new_file.new_tag('td')
        td_photo["class"] = "col-md-2 text-right pr-1"
        td_photo = build_conversations_profile_pic(
            html_doc_new_file, participant_pic, participant_contact_id,
            participant_large_pic, div_col_left, depth, td_photo)
        photo = copy.copy(td_photo)

        # td 2 - Name
        td_name = html_doc_new_file.new_tag('td')
        td_name = build_conversations_name(html_doc_new_file, thread_key,
                                           participant_name, div_col_right,
                                           depth, td_name)
        name = copy.copy(td_name)

        # td 3 - Thread Key
        td_thread_key = html_doc_new_file.new_tag('td')
        td_thread_key.append(str(new_thread_key))

        # td 4 - Contact Id
        td_contact_id = html_doc_new_file.new_tag('td')
        td_contact_id.append(str(participant_contact_id))

        # td 5 - Nickname
        td_nickname = html_doc_new_file.new_tag('td')
        td_nickname.append(str(participant_nickname))

        tr_tag_data = html_doc_new_file.new_tag('tr')
        tr_tag_data.append(td_photo)
        tr_tag_data.append(td_name)
        tr_tag_data.append(td_thread_key)
        tr_tag_data.append(td_contact_id)
        tr_tag_data.append(td_nickname)

        html_doc_new_file.table.tbody.append(tr_tag_data)

        # This is what will be visible
        if (str(participant_contact_id) != str(suspect_contact_id)):
            div_col_left.append(photo)
            div_col_right.append(name)
            div_row_col.append(div_col_left)
            div_row_col.append(div_col_right)
            div_empty_1 = html_doc_new_file.new_tag('div')
            div_empty_1["class"] = "col"
            div_empty_2 = html_doc_new_file.new_tag('div')
            div_empty_2["class"] = "col"
            div_row_col.append(div_empty_1)
            div_row_col.append(div_empty_2)

            div_conversation_group.append(div_row_col)

            # Check if isnt the last row
            if (i < results_lenght - 2):
                next_thread_key = results[i + 2][3]
                if next_thread_key != thread_key:
                    div_container_fluid.append(div_conversation_group)
            if (results_lenght == i + 1):
                div_container_fluid.append(div_conversation_group)

    html_doc_new_file.table.insert_before(div_container_fluid)

    new_file.seek(0)
    new_file.write(html_doc_new_file.prettify())
    new_file.truncate()
    if (depth == "complete"):
        extract_images(extract_conversation_list)
Esempio n. 6
0
def report_html_messages(template_path, depth):

    # Connect to database
    db_path = DB_PATH
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    cursor.execute(MESSAGES_PER_CONVERSATION_QUERRY)
    # Variable initialization
    thread_key = 0
    new_thread_key = 1
    last_sender = 0
    last_message_id = 0
    last_attachment_filename = ""
    web_img_url_counter = 0
    button_style_class = "btn btn-outline-light my-2 my-sm-0 fast-button"
    output_path = NEW_FILE_PATH
    for row in cursor:
        # Query fields
        new_thread_key = row[0]
        datetime = str(row[1])
        sender_id = str(row[2])
        sender_name = str(row[3])
        message = str(row[4])
        attachment_preview_url = str(row[5])
        attachment_playable_url = str(row[6])
        attachment_title = str(row[7])
        attachment_subtitle = str(row[8])
        attachment_type = str(row[9])
        attachment_url_mimetype = str(row[10])
        attachment_filename = str(row[11])
        reaction = str(row[12])
        reaction_sender = str(row[13])
        attachment_duration = str(row[14])
        message_id = str(row[15])

        # BeautifulSoup variables
        html_doc_new_file = ""

        has_header = []

        # If is the same conversation as previous..
        if thread_key == new_thread_key:
            try:
                previous_file_path = MESSAGES_PATH + str(thread_key) + ".html"
                f = open(previous_file_path, 'r', encoding='utf-8')
                html_doc_new_file = BeautifulSoup(f, features='html.parser')
                new_file = open(previous_file_path, 'w', encoding='utf-8')
                # Close file
                f.close()
            except IOError as error:
                print(error)
        # If is a new conversation..
        elif thread_key != new_thread_key:
            thread_key = new_thread_key
            new_file_path = MESSAGES_PATH + str(thread_key) + ".html"
            # Avoid file overwrite, check if file exists
            if Path(new_file_path).is_file():
                try:
                    f = open(new_file_path, 'r', encoding='utf-8')
                    html_doc_new_file = BeautifulSoup(f,
                                                      features='html.parser')
                    f.close()
                except IOError as error:
                    print(error)
            else:
                try:
                    # New file, get template_file
                    template_file = open(template_path, 'r', encoding='utf-8')
                    html_doc_new_file = BeautifulSoup(template_file,
                                                      features='html.parser')
                    # build header
                    if thread_key not in has_header:
                        html_doc_new_file = header(html_doc_new_file,
                                                   thread_key, depth)
                        has_header.append(thread_key)
                except IOError as error:
                    print(error)
            # Open according file
            new_file = open(new_file_path, 'w', encoding='utf-8')
        try:
            if not message or message == "" or message == 'None':
                fields = [
                    thread_key, attachment_type, attachment_preview_url,
                    attachment_playable_url, attachment_title,
                    attachment_subtitle, attachment_url_mimetype,
                    attachment_filename, attachment_duration, depth,
                    output_path, MSG_FILES_FOLDER_NAME
                ]
                td_message = html_doc_new_file.new_tag('td')
                td_message = handle_empty_messages(html_doc_new_file, fields,
                                                   td_message)
            elif "xma_web_url" in attachment_type:
                filetype = ''
                if (attachment_filename == "None"):
                    attachment_filename = attachment_filename + "(" + str(
                        web_img_url_counter) + ")" + ".jpg"
                    web_img_url_counter = web_img_url_counter + 1
                elif (attachment_filename.find('.') > 0):
                    filetype = ''
                else:
                    filetype = utils.get_filetype(attachment_preview_url)
                a_href_tag = html_doc_new_file.new_tag('a')
                a_href_tag["href"] = attachment_playable_url
                a_href_tag["target"] = "_new"
                a_href_tag["class"] = button_style_class
                a_href_tag["style"] = "color: white"
                a_href_tag.append("Play")
                if (depth == "fast"):
                    a_tag = html_doc_new_file.new_tag('a')
                    a_tag['class'] = button_style_class
                    a_tag['href'] = attachment_preview_url
                    a_tag['target'] = "_new"
                    a_tag.append("View Image")
                    td_message = html_doc_new_file.new_tag('td')
                    td_message.append(a_tag)
                    if attachment_playable_url != "None":
                        td_message.append(a_href_tag)
                    td_message.append(message + " - " + attachment_title +
                                      " - " + attachment_subtitle)
                elif (depth == "complete"):
                    extract_message_file(output_path, attachment_preview_url,
                                         attachment_filename, filetype,
                                         str(thread_key))
                    img_tag = html_doc_new_file.new_tag('img')
                    img_tag[
                        'src'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}{filetype}'
                    td_message = html_doc_new_file.new_tag('td')
                    td_message.append(img_tag)
                    if attachment_playable_url != "None":
                        td_message.append(a_href_tag)
                    td_message.append(message + " - " + attachment_title +
                                      " - " + attachment_subtitle)
            else:
                td_message = html_doc_new_file.new_tag('td')
                td_message.append(message)

            # New style

            suspect_contact_id = SUSPECT_ID

            div_container_fluid = html_doc_new_file.new_tag('div')
            if (suspect_contact_id == sender_id):
                div_container_fluid["class"] = "container-fluid w-80 mr-5"
            else:
                div_container_fluid["class"] = "container-fluid w-80 ml-5"

            fields = [
                suspect_contact_id, thread_key, datetime, sender_id,
                sender_name, td_message, reaction, reaction_sender, message_id,
                last_message_id, last_sender, attachment_filename,
                last_attachment_filename
            ]
            div_container_fluid = create_modern_message_style(
                html_doc_new_file, fields, div_container_fluid)

            last_sender = sender_id
            last_message_id = message_id
            if (attachment_filename != 'None'):
                last_filename = attachment_filename

            html_doc_new_file.table.insert_before(div_container_fluid)

            # Old Style

            tr_tag = html_doc_new_file.new_tag('tr')

            # Atention to field order. It must match the template_messages table headers
            fields = [
                thread_key, datetime, sender_id, sender_name, td_message,
                attachment_filename, attachment_playable_url,
                attachment_url_mimetype, attachment_type, reaction,
                reaction_sender, message_id
            ]
            tr_tag = create_message_table_row(html_doc_new_file, fields)

            html_doc_new_file.table.tbody.append(tr_tag)

            new_file.seek(0)
            new_file.write(html_doc_new_file.prettify())
            new_file.truncate()

            # Close file
            new_file.close()
        except IOError as error:
            print(error)
Esempio n. 7
0
def handle_empty_messages(html_doc_new_file, fields, td_message):

    thread_key = fields[0]
    attachment_type = fields[1]
    attachment_preview_url = fields[2]
    attachment_playable_url = fields[3]
    attachment_title = fields[4]
    attachment_subtitle = fields[5]
    attachment_url_mimetype = fields[6]
    attachment_filename = fields[7]
    attachment_duration = fields[8]
    depth = fields[9]
    output_path = fields[10]
    MSG_FILES_FOLDER_NAME = fields[11]

    # An attachment can be:
    #  - video: (preview_url + url video + title_text + subtitle_text)
    #  - attachment: (preview_url + title_text + subtitle_text + default_attachment_title)
    #  - image (preview_url + title_text + subtitle_text)
    #  - missed call (title_text + subtitle_text)

    # XXX (orainha) O que é xma_rtc?
    if attachment_type == "xma_rtc_ended_video":
        td_message.append("Ended " + attachment_title + " - " +
                          attachment_subtitle)
    elif attachment_type == "xma_rtc_missed_video":
        td_message.append(attachment_title + " at " + attachment_subtitle)
    elif "xma_rtc" in attachment_type:
        td_message.append(attachment_title + " - " + attachment_subtitle)
    # If it hasn't "xma_rtc", it would be something else
    if (depth == "fast"):
        if "image" in attachment_url_mimetype:
            # Get file type
            filetype = utils.get_filetype(attachment_playable_url)
            button_id = attachment_filename + filetype
            button = create_message_download_button(
                html_doc_new_file, button_id, 'btn_download_message_image',
                attachment_playable_url, "Download Image")
            td_message.append(button)
        elif "audio" in attachment_url_mimetype:
            # Audio filename already has filetype
            filetype = ''
            button = create_message_download_button(
                html_doc_new_file, attachment_filename,
                'btn_download_message_file', attachment_playable_url,
                "Download Audio")
            td_message.append(button)
        elif "video" in attachment_url_mimetype:
            button = create_message_download_button(
                html_doc_new_file, attachment_filename,
                'btn_download_message_file', attachment_playable_url,
                "Download Video")
            td_message.append(button)
        else:
            # Can be gifs, files
            filetype = ''
            if (attachment_filename.find('.') > 0):
                filetype = ''
            else:
                filetype = utils.get_filetype(attachment_playable_url)
                filetype = '.' + filetype
            button_id = attachment_filename + filetype
            button_value = ''
            if (attachment_preview_url != 'None'):
                button_value = attachment_preview_url
            elif (attachment_playable_url != 'None'):
                button_value = attachment_playable_url
            button = create_message_download_button(
                html_doc_new_file, button_id, 'btn_download_message_file',
                button_value, "Download File")
            td_message.append(button)
    elif (depth == "complete"):
        if "image" in attachment_url_mimetype:
            filetype = utils.get_filetype(attachment_playable_url)
            extract_message_file(output_path, attachment_preview_url,
                                 attachment_filename, filetype,
                                 str(thread_key))
            img_tag = html_doc_new_file.new_tag('img')
            img_tag[
                'src'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}{filetype}'
            td_message.append(img_tag)
        elif "audio" in attachment_url_mimetype:
            # Audio filename already has filetype
            filetype = ''
            extract_message_file(output_path, attachment_playable_url,
                                 attachment_filename, filetype,
                                 str(thread_key))
            href_tag = html_doc_new_file.new_tag('a')
            href_tag[
                'href'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}'
            href_tag['style'] = "color: white"
            href_tag.append("Audio - " + attachment_title + " - " +
                            attachment_subtitle)
            td_message.append(href_tag)
        elif "video" in attachment_url_mimetype:
            filetype = utils.get_filetype(attachment_preview_url)
            extract_message_file(output_path, attachment_preview_url,
                                 attachment_filename, filetype,
                                 str(thread_key))
            extract_message_file(output_path, attachment_playable_url,
                                 attachment_filename, '', str(thread_key))
            img_tag = html_doc_new_file.new_tag('img')
            # Need to add image filetype on this case, filename ends like '.mp4' (not suitable to show an image)
            img_tag[
                'src'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}{filetype}'
            duration = "["+attachment_duration + \
                "s]" if attachment_duration != "None" else ""
            title = " - " + attachment_title if attachment_title != "None" else ""
            subtitle = " - " + attachment_subtitle if attachment_subtitle != "None" else ""
            img_tag.append("Video " + duration + title + subtitle)
            href_tag = html_doc_new_file.new_tag('a')
            # Video filename already has filetype
            href_tag[
                'href'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}'
            href_tag['style'] = "color: white"
            href_tag.append(img_tag)
            td_message.append(href_tag)
        else:
            filetype = ''
            # if filename has his filetype written...
            if (attachment_filename.find('.') > 0):
                filetype = ''
            else:
                filetype = utils.get_filetype(attachment_playable_url)

            if (attachment_preview_url != 'None'):
                extract_message_file(output_path, attachment_preview_url,
                                     attachment_filename, filetype,
                                     str(thread_key))
                img_tag = html_doc_new_file.new_tag('img')
                img_tag[
                    'src'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}{filetype}'
                td_message.append(img_tag)

            elif (attachment_playable_url != 'None'):
                extract_message_file(output_path, attachment_playable_url,
                                     attachment_filename, filetype,
                                     str(thread_key))
                p_tag = html_doc_new_file.new_tag('p')
                p_tag.append(attachment_filename)
                href_tag = html_doc_new_file.new_tag('a')
                href_tag[
                    'href'] = f'..\{MSG_FILES_FOLDER_NAME}\{str(thread_key)}\{attachment_filename}' + '.' + filetype
                href_tag['style'] = "color: white"
                href_tag.append(p_tag)
                td_message.append(href_tag)
    return td_message
Esempio n. 8
0
def report_html(depth):
    global NEW_FILE_PATH
    # Connect to database
    conn = sqlite3.connect(DB_PATH)
    c = conn.cursor()
    c.execute(CONTACTS_QUERRY)

    # Get template and create new file
    template_file = open(CONTACTS_TEMPLATE_FILE_PATH, 'r', encoding='utf-8')
    html_doc_new_file = BeautifulSoup(template_file, features='html.parser')
    new_file = open(NEW_FILE_PATH + "contacts.html", 'w', encoding='utf-8')
    template_file.close()
    extract_contact_list = list()
    for row in c:
        # Query fields
        contact_id = str(row[0])
        contact_pic = str(row[1])
        contact_name = str(row[2])
        contact_phone = str(row[3])
        contact_email = str(row[4])
        contact_large_pic = str(row[5])
        # Set default values to 'None'
        if contact_phone == 'None':
            contact_phone = "No Phone"
        if contact_email == 'None':
            contact_email = "No Email"
        try:
            tr_tag = html_doc_new_file.new_tag('tr')
            # td 1
            td_id = html_doc_new_file.new_tag('td')
            td_id.append(contact_id)
            # td 2
            filetype = utils.get_filetype(contact_large_pic)
            if (depth == 'fast'):
                td_download_photo = html_doc_new_file.new_tag('td')
                button_tag = html_doc_new_file.new_tag('button')
                button_tag['id'] = str(contact_id) + filetype
                button_tag[
                    'class'] = 'btn_download_contact_image btn btn-outline-dark my-2 my-sm-0'
                button_tag['value'] = contact_large_pic
                button_tag.append('Download Image')
                td_download_photo.append(button_tag)
            elif (depth == 'complete'):
                # Download images later
                contact = [
                    NEW_FILE_PATH, contact_pic, contact_large_pic, contact_id,
                    filetype
                ]
                extract_contact_list.append(contact)
                td_photo = html_doc_new_file.new_tag('td')
                href_tag = html_doc_new_file.new_tag('a')
                href_tag[
                    'href'] = f'contacts\images\large\{contact_id}{filetype}'
                img_tag = html_doc_new_file.new_tag('img')
                img_tag[
                    'src'] = f'contacts\images\small\{contact_id}{filetype}'
                img_tag['id'] = 'imgContact'
                href_tag.append(img_tag)
                td_photo.append(href_tag)
            # td 3
            td_name = html_doc_new_file.new_tag('td')
            td_name.append(str(contact_name))
            # td 4
            td_email = html_doc_new_file.new_tag('td')
            td_email.append(str(contact_email))
            # td 5
            td_phone = html_doc_new_file.new_tag('td')
            td_phone.append(str(contact_phone))

            # tr append
            tr_tag.append(td_id)

            if (depth == 'fast'):
                tr_tag.append(td_download_photo)
            elif (depth == 'complete'):
                tr_tag.append(td_photo)

            tr_tag.append(td_name)
            tr_tag.append(td_email)
            tr_tag.append(td_phone)
            html_doc_new_file.table.tbody.append(tr_tag)
        except IOError as error:
            print(error)
            break
    new_file.seek(0)
    new_file.write(html_doc_new_file.prettify())
    new_file.truncate()
    new_file.close()
    if (depth == 'complete'):
        extract_images(extract_contact_list)