Let's use the Python version of the Confluence API module.

I've tried using the Python version of the Confluence API module, so I'll introduce it.

Introduction / 20171227 Addendum

For those of you who arrived at this article thinking that there is a python module for Confluence.

As of December 2017, the repository that was in Bitbucket at the time of writing this article was migrated to GitHub. It will be the following repository.

As I moved to GitHub, I feel that it has become easier to check for updates and issue pull requests!

Python API to Confluence

--Package (pypi): https://pypi.python.org/pypi/confluence --Documentation: Python confluence module Documentation (via Sphinx) --Repository: https://bitbucket.org/phoebian/confluence

The repository Bitbucket is like python & Atlassian!

Installation

I'll put it in with pip ~ (I'm sorry for the omission ...)

% sudo pip install confluence
Password:
Downloading/unpacking confluence
Downloading confluence-0.1.tar.gz
…
Successfully installed confluence
Cleaning up...

Get documentation on the command line

The authentication information can be omitted by creating a configuration file called config.ini. This time, I will specify the parameters when creating the object.

The target Confluence is Confluence for Jenkins.

python


>>> from confluence import Confluence
>>> conf = Confluence(profile=None, url="https://wiki.jenkins-ci.org", username="xxx", password="xxxx")
>>> o = conf.getPage("Jenkins study session","JA")
>>> 
>>> print o['title']
Jenkins study session
>>> 
>>> print o['content'][0:100]       
h2.Jenkins study session

h3.Tokyo

* [1st Hudson Study Session|Hudson study session]
* [The 2nd Jenkins Study Group]
* [The 3rd Jenkins Study Group]
* [4th Jenkins
>>> o['id']
'58000672'
>>> 

Confluence for Jenkins seems to be Version 3.4.7, but it was ok for reading.

About writing

The original package (https://pypi.python.org/pypi/confluence) is mainly Page, not for posting / updating Blogs, only basic ones.

Page operation

In the above sample, if you change the content part of the Page object and set it to conf.storePageContent (o), it will be overwritten and updated. If there is no id, it will be a new registration.

Blog writing

Well, since the original Confluence API is simple, I put the one corresponding to the method for Blog in my repository. (I also added a method to force another specified user to watch the completed page)

Click here for a sample.

#Create an object for posting
newPost = {}
newPost['content'] = content
newPost['title'] = title
newPost['space'] = '~myself'
newPost['author'] = 'My login account'

#Register as Blog
res = conf.storeBlogEntry(newPost)
print res['id']


#Attach tags (page),Blog common)
conf.addLabelByName(u'Advent calendar',res['id'])

#Let me watch the content that I was forced to do (page),Blog common)
conf.watchPageForUser(res['id'], "The account of the person you want to watch")

Covered with REST API

There are some methods that are not implemented in XML-RPC / SOAP of Confluence API, but I will introduce them a little because they can be operated using REST.

Actually, I captured the process executed from the Confluence screen and searched for something like "What kind of request are you sending?" (It's strange)

On the command line, you can authenticate with your account-> like the specified content by doing the following.

bash


curl https://URL of confluence/rest/likes/1.0/content/__ID__/likes -X POST --user user:passwd

python


import requests

# res['id']Is the content ID
url = "https://URL of confluence/rest/likes/1.0/content/%s/likes" % res['id']
requests.post(url, auth=(account,password))

Good! Withdrawal is OK if you change it to dislike.

Recommended Posts

Let's use the Python version of the Confluence API module.
Let's use the API of the official statistics counter (e-Stat)
Let's use the open data of "Mamebus" in Python
[Python] Use the Face API of Microsoft Cognitive Services
Test the version of the argparse module
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
Use the Flickr API from Python
Let's touch the API of Netatmo Weather Station with Python. #Python #Netatmo
What is the default TLS version of the python requests module?
Pass the path of the imported python module
About the virtual environment of python version 3.7
[Python] Try pydash of the Python version of lodash
Check the path of the Python imported module
Try the python version of emacs-org parser orgparse
[Python] Let's execute the module regularly using schedule
Use the latest version of PyCharm on Ubuntu
Use OpenSeesPy regardless of OS or Python version
[Python] A rough understanding of the logging module
Try using the collections module (ChainMap) of python3
Let's use different versions of SQLite3 from Python3!
Use the nghttp2 Python module from Homebrew from pyenv's Python
[Python] Get the text of the law from the e-GOV Law API
[python] Get the list of classes defined in the module
Let's break down the basics of TensorFlow Python code
[Python] Let's change the URL of the Django administrator site
Align the version of chromedriver_binary
Let's use def in python
Let's use python janome easily
Use Trello API with python
Towards the retirement of Python2
Use Twitter API with Python
About the Python module venv
Automatic update of Python module
About the ease of Python
Version upgrade of python Anaconda
Check OpenSSL version of python 2.6
Call the API with python3.
Use subsonic API with python3
About the features of Python
Use e-Stat API from Python
The Power of Pandas: Python
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
Put the latest version of Python on linux (Debian) on Chromebook
Why can I use the module by importing with python?
Make the display of Python module exceptions easier to understand
View using the python module of Nifty Cloud mobile backend
[Python] I tried collecting data using the API of wikipedia
Let's use the distributed expression of words quickly with fastText!
2015-11-26 python> Display the function list of the module> import math> dir (math)
Let's automatically display the lyrics of the song being played on iTunes in Python (improved version)
[Python] Tuple version of prefecture pull-down
Let's use usercustomize.py instead of sitecustomize.py
The story that the version of python 3.7.7 was not adapted to Heroku
The story of Python and the story of NaN
Raise the version of pyenv itself
How to use the optparse module
Wrap (part of) the AtCoder Library in Cython for use in Python
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Hit the Sesami API in Python