def publish(soup, args): client = ConfluenceAPI(username=args.username, password=args.password, uri_base=args.endpoint) EXPAND_FIELDS = 'body.storage,space,ancestors,version' content = client.get_content_by_id(content_id=args.page_id, expand=EXPAND_FIELDS) content_data = { 'id': args.page_id, 'type': 'page', #'space': {'key': space_key}, 'title': 'New Page', 'body': { 'storage': { 'value': str(soup), 'representation': 'storage' } }, #'ancestors': [] if not ancestor_id else [{'id': ancestor_id}] "version": { "number": content['version']['number'] + 1 }, } client.update_content_by_id(content_data=content_data, content_id=args.page_id)
def confluence(html, metadata): # Create API object. api = ConfluenceAPI(g_user, g_pass, g_confluence_url) update_content = False url = '' current_history = 0 update_content_id = '' # Check if confluence_id is not null and refer to a valid post if metadata['confluence_id'] is not None: content = api.get_content_by_id(metadata['confluence_id']) if content is not None: update_content = True current_history = content['version']['number'] update_content_id = metadata['confluence_id'] logging.info('updating post with given id') # Check if space is available if (metadata['confluence_space'] is not None) and (not update_content): space = api.get_space_information(metadata['confluence_space']) if space is None: raise Exception('Space not found') # Check if title is unique if (metadata['title'] is not None) and (not update_content): content = api.get_content(title=metadata['title']) if content is not None: if content['size'] > 0: if g_update_title: update_content = True found_id = content['results'][0]['id'] found_post = api.get_content_by_id(found_id) if found_post is not None: current_history = found_post['version']['number'] update_content_id = found_id logging.info('Updating duplicate Title') else: raise Exception('Title is found but not updating') if not update_content: post_content = { "type": "page", "title": metadata['title'], "space": { "key": metadata['confluence_space'] }, "body": { "storage": { "value": html, "representation": "storage" } }, "ancestors": [{ "id": metadata['confluence_parent_id'] }] } res = api.create_new_content(post_content) links = res['_links'] url = links['base'] + links['webui'] else: post_content = { "id": update_content_id, "type": "page", "title": metadata['title'], "space": { "key": metadata['confluence_space'] }, "version": { "number": current_history + 1, "minorEdit": False }, "body": { "storage": { "value": html, "representation": "storage" } } } res = api.update_content_by_id(post_content, update_content_id) links = res['_links'] url = links['base'] + links['webui'] return url