from bs4 import BeautifulSoup
from atlassian import Confluence
confluence = Confluence(
token="my_token",
cloud=True,
)
page_id = 00000000
page = confluence.get_page_by_id(page_id, expand="body.view,version.number")
page_content = page['body']['storage']['value']
version = page['version']['number'] + 1
soup = BeautifulSoup(page_content, 'html.parser')
table = soup.find('table', {'class': 'relative-table wrapped tf-macro'})
headers = [header.text.strip() for header in table.find_all('th')]
table_data = {header: [] for header in headers}
for row in table.find_all('tr')[1:]:
data = [td.text.strip() for td in row.find_all('td')]
for header, value in zip(headers, data):
table_data[header].append(value)
new_value = {
'Change Created': 'NEW_CHANGE',
'Stage': 'PROD/LIVE',
'Valid until': 'NEW_DATE',
'Status': 'NEW_STATUS',
'Notes': 'NEW_NOTES'
}
for header, value in new_value.items():
table_data[header].insert(0, value)
updated_table_html = "<table>"
updated_table_html += "<tr>" + "".join([f"<th>{header}</th>" for header in table_data.keys()]) + "</tr>"
for row in zip(*table_data.values()):
updated_table_html += "<tr>" + "".join([f"<td>{data}</td>" for data in row]) + "</tr>"
updated_table_html += "</table>"
updated_content = f"{soup}\n{updated_table_html}"
# Update page
confluence.update_page(
page_id=0000000,
title='Certificate',
body= {
"storage": {
"value": updated_content
}
},
representation= 'storage',
always_update=True,
type='page',
minor_edit=False,
)
----------------------------------------
I get this error
version = self.history(page_id)["lastUpdated"]["number"] + 1
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'lastUpdated'
Not able to understand what is the error here.
This is my first time using the Confluence API, any help in good direction would be really helpful