I want to access the source of Gliffy diagrams in Confluence, for example to change one color with another in a large number of diagrams in a number of pages.
I managed to read / update / write / reload a Gliffy diagram, but displays a "Drat, error 500 diagram under construction" error with an invitation to contact my administrator.
What I did: inspired by @Tim in How to download a Confluence page attachment with Python?, I wrote the following:
confluence = Confluence(
url= CONFLUENCE_URL,
username=CONFLUENCE_USER_NAME,
password=CONFLUENCE_PASSWORD)
def test_get_page_content():
page_id=852512337
attachments_container = confluence.get_attachments_from_content(page_id=page_id, start=0, limit=500)
attachments = attachments_container['results']
for attachment in attachments:
title = attachment['title']
fname = attachment['title']
download_link = confluence.url + attachment['_links']['download']
r = requests.get(download_link, auth=(confluence.username, confluence.password))
if r.status_code == 200:
with open(fname, "wb") as f:
file_text2 = r.content
# print(file_text2)
# file_text = r.content.decode(encoding='utf-16')
string_content = ""
for bits in r.iter_content():
try:
string_content = string_content + bits.decode()
except Exception:
pass
edited = re.sub('ff9900', 'CCCCCC', string_content)
f.write(edited.encode())
confluence.attach_file(fname, name=title, content_type=None, page_id=page_id, title=title, space=None, comment=None)
When I look at the file in a text editor, it looks like normal JSON, just like a file exported manually in Gliffy format from the Gliffy diagram.