From 56bd19009ca39a1ae5967c639c449d255ca58e5b Mon Sep 17 00:00:00 2001 From: Tim Jaacks <tim.jaacks@seco.com> Date: Mon, 23 Oct 2023 11:32:26 +0200 Subject: [PATCH] Confluence: add helper script to get page content This can be helpful if something is configurable in the GUI editor and we can't figure out to do the same thing via the API. --- scripts/confluence_get_page_content.py | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 scripts/confluence_get_page_content.py diff --git a/scripts/confluence_get_page_content.py b/scripts/confluence_get_page_content.py new file mode 100755 index 00000000..c618b846 --- /dev/null +++ b/scripts/confluence_get_page_content.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import argparse + +import requests +from atlassian import Confluence + +import common + + +def main(): + # Create parser and add possible command line arguments + parser = argparse.ArgumentParser() + + parser.add_argument( + "--confluence-url", + help="""URL to the Confluence instance""", + dest="confluence_url", + default=common.CONFLUENCE_URL, + ) + parser.add_argument( + "--username", + help="""Username for the Confluence API""", + dest="username", + required=True, + ) + + parser.add_argument( + "--token", + help="""Token for the Confluence API""", + dest="token", + required=True, + ) + + parser.add_argument( + "--space-id", + help="""Confluence space ID or name""", + dest="space_id", + required=True, + ) + + parser.add_argument( + "--page-name", + help="""Name of the page""", + dest="page_name", + required=True, + ) + + # Parse command line arguments + args, _ = parser.parse_known_args() + + # Connect to confluence + confluence = Confluence( + url=args.confluence_url, + username=args.username, + password=args.token, + ) + + try: + # Get page including its content. See for reference: + # https://community.atlassian.com/t5/Confluence-questions/how-to-get-full-content-body-html-using-confluence-REST-API/qaq-p/710532 + page = confluence.get_page_by_title( + args.space_id, args.page_name, expand="body.storage" + ) + + except requests.exceptions.HTTPError as e: + exit(f"ERROR: {e}") + + print(page["body"]["storage"]["value"]) + + +if __name__ == "__main__": + main() -- GitLab