Python 2.7 기준
파이썬 설치된 곳에서 아래의 명령 실행
pip --trusted-host pypi.org --trusted-host files.pythonhosted.org download atlassian-python-api
대략 아래와 같은 파일들을 다운로드받게된다.
atlassian-python-api-1.14.4.tar.gz certifi-2019.9.11-py2.py3-none-any.whl chardet-3.0.4-py2.py3-none-any.whl idna-2.8-py2.py3-none-any.whl oauthlib-3.1.0-py2.py3-none-any.whl requests-2.22.0-py2.py3-none-any.whl requests_oauthlib-1.3.0-py2.py3-none-any.whl six-1.13.0-py2.py3-none-any.whl urllib3-1.25.7-py2.py3-none-any.whl
다운로드 받은 파일들을 모두 원하는 머신으로 옮긴 후, 해당 디렉토리에서 커맨드 창을 열어서 아래와 같은 명령을 입력한다.
pip install --no-index --find-links=. atlassian-python-api
–find-links 뒤에는 점 하나만 찍어주고, 한 칸 띄운 후 패키지 이름을 적어주는 것에 유의.
2.7 기준에서만 발생하는 에러인 거 같은데, Jira8 모듈에서 에러가 난다.
(C:\Python27\Lib\site-packages\atlassian\jira8.py) # coding=utf-8 import logging from .jira import Jira log = logging.getLogger(__name__) class Jira8(Jira): # methods migrated into main module pass <--- 추가
# -*- coding:euc-kr -*- from atlassian import Confluence c = Confluence(url='http://wiki.somewhere.com/', username='seongmkim', password='xxxx') parent_id = c.get_page_id(space='~seongmkim', title=u'김성민’s Home'.encode('utf-8')) if parent_id != None: status = c.create_page(space='~seongmkim', title='this is title', body='hello <strong>world</strong>', parent_id=parent_id) print status
그냥 HTML로 적어주면 된다.
# -*- coding:euc-kr -*- from atlassian import Confluence c = Confluence(url='http://wiki.somewhere.com/', username='seongmkim', password='xxxx') page_space = '~seongmkim' page_title = 'hello world' parent_title = u'김성민’s Home'.encode('utf-8') # 해당 이름의 페이지기 이미 존재한다면 삭제 prev_id = c.get_page_id(space=page_space, title=page_title) if prev_id != None: c.remove_page(page_id=prev_id) # 부모 페이지가 존재한다면... parent_id = c.get_page_id(space=page_space, title=parent_title) if parent_id != None: msg = """ <table> <tr> <th>One</th> <th>Two</th> </tr> <tr> <td>1</td> <td>2</td> </tr> </table> """ status = c.create_page(space=page_space, title=page_title, body=msg, parent_id=parent_id) print status
# -*- coding:euc-kr -*- import json import codecs from atlassian import Confluence c = Confluence(url='http://wiki.somewhere.com/', username='seongmkim', password='xxxx') page_space = '~seongmkim' page_title = 'hello world' parent_title = u'김성민’s Home'.encode('utf-8') page_id = c.get_page_id(space=page_space, title=page_title) if page_id != None: page = c.get_page_by_id(page_id, expand='body.storage') file = codecs.open("page.json", "w", "utf-8-sig") file.write(json.dumps(page))
아래와 같은 JSON 형식으로 출력이 나온다.
body.storage.value 부분읅 읽으면 되긴 하는데, 문제는 HTML 형식이다. 파이썬에 당연히 HTML 파서가 있긴 하겠으나, HTML 특성상 특정값을 읽어오기는 쉽지 않을 듯?
{ "status": "current", "body": { "_expandable": { "export_view": "", "styled_view": "", "editor": "", "anonymous_export_view": "", "view": "" }, "storage": { "_expandable": { "content": "/rest/api/content/92275574" }, "representation": "storage", "value": "<table>\n <tbody><tr>\n <th>One</th>\n <th>Two</th>\n </tr>\n <tr>\n <td>1</td>\n <td>2</td>\n </tr>\n </tbody></table>" } }, "title": "hello world", "_expandable": { "operations": "", "restrictions": "/rest/api/content/92275574/restriction/byOperation", "ancestors": "", "container": "/rest/api/space/~seongmkim", "descendants": "/rest/api/content/92275574/descendant", "space": "/rest/api/space/~seongmkim", "version": "", "metadata": "", "children": "/rest/api/content/92275574/child", "history": "/rest/api/content/92275574/history" }, "extensions": { "position": 27 }, "_links": { "edit": "/pages/resumedraft.action?draftId=92275574", "self": "http://wiki.somewhere.com/rest/api/content/92275574", "tinyui": "/x/dgOABQ", "base": "http://wiki.somewhere.com", "webui": "/display/~seongmkim/hello+world", "context": "", "collection": "/rest/api/content" }, "type": "page", "id": "92275574" }
ac:task 태그를 활용한다. 이렇게 생성하면, ac-task-id 태그가 없어서 그런지, 체크 박스를 체크할 수가 없는데, 페이지를 브라우저에서 한번 edit 했다가 저장하면 된다.
def html_escape(text): text = text.replace(u"&", u"&") text = text.replace(u"<", u"<") text = text.replace(u">", u">") text = text.replace(u"\"", u""") text = text.replace(u"'", u"'") text = text.replace(u"/", u"/") text = text.replace(u"`", u"`") text = text.replace(u"=", u"=") # text = text.replace(u" ", u" ") return text html_affected = [] html_affected.append("<ac:task-list>") for line in affected.decode("euc-kr").split("\n"): line = html_escape(line) html_affected.append(u"<ac:task><ac:task-status>incomplete</ac:task-status><ac:task-body>{0}</ac:task-body></ac:task>".format(line)) html_affected.append("</ac:task-list>")