File size: 1,076 Bytes
56d74b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# coding=utf-8
from atlassian import Confluence

"""This example shows how to use the cql
   More detail documentation located here https://developer.atlassian.com/server/confluence/advanced-searching-using-cql
"""

confluence = Confluence(url="http://localhost:8090", username="admin", password="admin")

WORD = "componentname"


def search_word(word):
    """
    Get all found pages with order by created date
    :param word:
    :return: json answer
    """
    cql = "siteSearch ~ {} order by created".format(word)
    answers = confluence.cql(cql)
    for answer in answers.get("results"):
        print(answer)


def search_word_in_space(space, word):
    """
    Get all found pages with order by created date
    :param space
    :param word:
    :return: json answer
    """
    cql = "space.key={} and (text ~ {})".format(space, word)
    answers = confluence.cql(cql, expand="space,body.view")
    for answer in answers.get("results"):
        print(answer)


if __name__ == "__main__":
    search_word(word=WORD)
    search_word_in_space(space="TST", word=WORD)