0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

APIでコンフルエンスのグループを取得してExcelに書き出す

Last updated at Posted at 2022-04-27

はじめに

コンフルエンスのグループ情報を取得してExcelに書き出す処理の実装です。
実務で地味に使ってるので記事にしました。

その内Githubに集約していきます。

数年前に書いたモノなので恥ずかしいコードになってるのはご容赦ください。


ライブラリ

openpyxlはpipで追加インストール

requests、json、astは標準ライブラリです。

コード

getgroups.py
import openpyxl
import requests
import json
import ast

auth = ("hogehoge@hoge.co.jp", "APIキー情報")

def GetGroups():
    wb = openpyxl.load_workbook("test.xlsx")
    sht = wb['Sheet1']
    url = "https://xxxx.atlassian.net/wiki/rest/api/group"

    headers = {
        "Accept": "application/json"
    }

    query = {
    'limit': 500 #500 #取得するグループのリミット数
    }

    response = requests.request(
        "GET",
        url,
        auth=auth,
        headers=headers,
        params=query
    )

    parse_response = json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": "))

    group_name_dict = {}

    dict_response = json.loads(parse_response)

    dict_convert_lists = dict_response['results']

    i = 0

    for value in dict_convert_lists:

        con_dict_value = ast.literal_eval(str(value))

        group_name_dict[i] = con_dict_value['name']
        print(con_dict_value['name'])

        i += 1

        sht.cell(i, 1).value = con_dict_value['name']

    wb.save("test.xlsx")

こんな感じに出力されます。
image.png


詳細

コンフルでAPIキーを作成して認証情報を組み込みます
auth = ("hogehoge@hoge.co.jp", "APIキー情報")

def GetGroups():
  書き出すExcelファイルとシートを記述
    wb = openpyxl.load_workbook("test.xlsx")
    sht = wb['Sheet1']

  confluence urlを記述
  url = "https://xxxx.atlassian.net/wiki/rest/api/group"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?