anthony revised this gist . Go to revision
1 file changed, 49 insertions
confluence_get_article.sh(file created)
@@ -0,0 +1,49 @@ | |||
1 | + | #!/bin/bash | |
2 | + | ||
3 | + | # 1. Указать реквизиты доступа к confluence | |
4 | + | USERNAME="" | |
5 | + | PASSWORD="" | |
6 | + | CONFLUENCE_URL="" | |
7 | + | OUTPUT_PATH="./confluence/" | |
8 | + | ||
9 | + | # 2. Вызвать: ./confluence_get_article.sh <page_id> | |
10 | + | ||
11 | + | ################################################################## | |
12 | + | ||
13 | + | if [ $# -lt 1 ]; then | |
14 | + | echo "Usage: $0 <article_id>" | |
15 | + | exit 1 | |
16 | + | fi | |
17 | + | ||
18 | + | command -v curl >/dev/null 2>&1 || { echo >&2 "Error: curl is required but not installed."; exit 1; } | |
19 | + | command -v jq >/dev/null 2>&1 || { echo >&2 "Error: jq is required but not installed."; exit 1; } | |
20 | + | ||
21 | + | DELAY=1 | |
22 | + | ARTICLE_ID="$1" | |
23 | + | API_ENDPOINT="${CONFLUENCE_URL}/rest/api/content/${ARTICLE_ID}?expand=body.storage,children.page" | |
24 | + | ||
25 | + | echo | |
26 | + | echo "Downloading: $API_ENDPOINT" | |
27 | + | ||
28 | + | response=$(curl -s -u "$USERNAME:$PASSWORD" -H "Accept: application/json" "${API_ENDPOINT}") | |
29 | + | if [ $? -ne 0 ]; then | |
30 | + | echo "Error: Failed to retrieve article" | |
31 | + | fi | |
32 | + | ||
33 | + | error_message=$(echo "$response" | jq -r '.message' 2>/dev/null) | |
34 | + | if [ -n "$error_message" ] && [ "$error_message" != "null" ]; then | |
35 | + | echo "API Error: $error_message" | |
36 | + | else | |
37 | + | title=$(echo "$response" | jq -r .title) | |
38 | + | content=$(echo "$response" | jq -r .body.storage.value) | |
39 | + | [ ! -d "$OUTPUT_PATH" ] && mkdir -p "$OUTPUT_PATH" | |
40 | + | echo "<html><body>$content</body></html>" > "$OUTPUT_PATH/$title.html" | |
41 | + | echo "Saved as: $OUTPUT_PATH/$title.html" | |
42 | + | ||
43 | + | child_ids=$(echo "$response" | jq -r '.children.page.results[]?.id' 2>/dev/null) | |
44 | + | for child_id in $child_ids; do | |
45 | + | echo "Downloading child page ID: $child_id" | |
46 | + | sleep $DELAY | |
47 | + | ./confluence_get_article.sh "$child_id" | |
48 | + | done | |
49 | + | fi |
Newer
Older