Python-atlassian-api

import os

from atlassian import Confluence

import pandas as pd


confluence = Confluence(

    url=URL,

    username=os.environ["CONFLUENCE_USERNAME"],

    password=os.environ["CONFLUENCE_TOKEN"],

    cloud=True

)


space = "SPACE"

page_title = "testpage"

page = confluence.get_page_by_title(space=space, title=page_title)

page_id = page["id"]

page_content = confluence.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]


header = "Insert my table here"

start_header_index = page_content.find(header)

insert_index = start_header_index + len(header) + 5  # 5 is for '</hX>'

df = pd.DataFrame({"col1": [1, 2], "col2": ["a", "b"]})

table_html = df.to_html(index=False)


top_page_content = page_content[:insert_index]

bottom_page_content = page_content[insert_index:]

new_page_content = top_page_content + table_html + bottom_page_content


confluence.update_page(page_id=page_id, title=title, body=new_page_content)


confluence.get_page_by_id(page_id=page_id)

orig_body = confluence.get_page_by_id(page_id, expand="body.storage")["body"]["storage"]["value"]


confluence.get_page_property(page_id=page_id, page_property_key="content-appearance-published")

confluence.get_page_properties(page_id=page_id)