Example #1
0
class ConfluenceClient(object):

	def __init__(self, url, username, password):
		self.confluence = Confluence(url, username, password)

	"""
	Get a array of all page titles (including children) in a space.	
	"""
	def get_page_names(self, space_key):
		has_next = True	
		page_names = []
		start = 0
		limit = 25
		while has_next is True:
			pages = self.confluence.get_pages(space_key, start, limit).json()
			results = pages['results']
			for page in results:
				page_names.append(page['title'])
			if 'next' in pages['_links']:
				start = pages['start'] + pages['limit']
			else:
				has_next = False
		return page_names
	

	"""
	Get count of all pages in a space
	"""
	def get_page_count(self, space_key):
		return len(self.get_page_names(space_key))
	
	"""
	Create an empty page in the give Confluence space
	"""
	def create_empty_page(self, space_key, title, parent_page_id=None):
		if parent_page_id is not None:
			ancestors = [{ 'id': parent_page_id }]
		else:
			ancestors = None		

		return self.confluence.create_page(space_key, title, ancestors, '')


	"""
	Write content to file
	"""
	def write_to_file(filepath, content):
		outfile = open(filepath, 'w')
		outfile.write(content)
		outfile.close()