if len(values) == 0: flag = False print("Extracted all pages excluding restricts") else: for value in values: page_ids.append(value.get("id")) return page_ids def check_unknown_attachment_in_space(confluence, space_key): """ Detect errors in space :param confluence: :param space_key: :return: """ page_ids = get_all_pages_ids(confluence, space_key) print("Start review pages {} in {}".format(len(page_ids), space_key)) for page_id in page_ids: link = confluence.has_unknown_attachment_error(page_id) if len(link) > 0: print(link) if __name__ == "__main__": space_list = confluence.get_all_spaces() for space in space_list: print("Start review {} space".format(space["key"])) check_unknown_attachment_in_space(confluence, space["key"])
class Readme2Confluence: """ Main class that will create the Confluence page from Markdown """ def __init__(self, url, username, password, space): self.confluence = Confluence(url, username=username, password=password) spaces = self.confluence.get_all_spaces(start=0, limit=500) if any(s for s in spaces if s["name"] == space): self.space = space else: raise ValueError("{} is not valid Confluence Space".format(space)) def get_page_id(self, title): """ Retrieve the ID of a page using it's title This is basically a small wrapper around confluence.get_page_id(). The main reason for the wrapper is to better handle pages that aren't found by raising an exception """ page_id = self.confluence.get_page_id(self.space, title) if page_id is None: raise ValueError("{} is not a valid page title in {}".format( title, self.space)) return page_id def get_page_html(self, title): """ Retrieve a confluence page and return it as a HTML (string) """ page_id = self.get_page_id(title) return self.confluence.get_page_by_id(page_id) def send2confluence(self, title, parent_title=None, md_file=None, md_text=""): """ Method that creates the confluence page. Page will either be created or updated depending on what is required. """ if md_file is None: body = md2html(md_text) else: body = md2html(get_md_text(md_file)) parent_id = None if parent_title is None else self.get_page_id( parent_title) page_id = self.confluence.get_page_id(self.space, title) if page_id is None: ret = self.confluence.create_page(self.space, title, body, parent_id=parent_id, type='page', representation='storage') else: ret = self.confluence.update_page(page_id, title, body, parent_id=parent_id, type='page', representation='storage') return ret