Created
October 14, 2011 13:18
-
-
Save dirkk0/1287068 to your computer and use it in GitHub Desktop.
pushes content into Confluence as a child of a given ID.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, urllib, urllib2 | |
class Pusher: | |
def __init__(self, url, username, password, baseId, tokenId): | |
self.url = url | |
self.username = username | |
self.password = password | |
self.baseId = baseId | |
self.spaceKey = '~'+username | |
self.tokenId = tokenId | |
def pushText(self, url,username,password,spaceKey,baseId, tokenId, content): | |
passman = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
passman.add_password(None, url, username, password) | |
authhandler = urllib2.HTTPBasicAuthHandler(passman) | |
opener = urllib2.build_opener(authhandler) | |
urllib2.install_opener(opener) | |
# content = open('text.md.txt','r').read() | |
mode = 'edit' | |
if mode == 'new': | |
link = url+"confluence/pages/doeditpage.action?pageId=" + BaseId | |
f = urllib2.urlopen(link) | |
c = f.read() | |
parentPageString = c.split("name=\"title")[1].split('value=\"')[1].split('\"')[0] | |
link = url+'confluence/pages/createpage.action?spaceKey=%s&fromPageId=%s' % (spaceKey, BaseId) | |
f = urllib2.urlopen(link) | |
c = f.read() | |
draftId = c.split("name=\"draftId")[1].split('value=\"')[1].split('\"')[0] | |
print draftId | |
link = url+"confluence/pages/docreatepage.action?pageId=" + baseId | |
params = urllib.urlencode({ | |
'atl_token':tokenId, | |
'fromPageId':baseId, | |
'spaceKey':spaceKey, | |
'title':'BTITLE', | |
'parentPageString': parentPageString, | |
'moveHierarchy':'true', | |
'draftId':draftId, | |
'content': content, | |
'newSpaceKey':spaceKey | |
}) | |
f = urllib2.urlopen(link, params) | |
c = f.read() | |
# o = open('out.txt','w') | |
# o.write(c) | |
if 'errorMessage error' in c: | |
print 'No errors' | |
else: | |
errorMessage = c.split("errorMessage\">")[1].split('</span>')[0].strip() | |
print 'ERROR' | |
print errorMessage | |
else: | |
link = url+"confluence/pages/doeditpage.action?pageId=" + baseId | |
f = urllib2.urlopen(link) | |
c = f.read() | |
version = c.split("originalVersion")[1].split('value=\"')[1].split('\"')[0] | |
title = c.split("name=\"title")[1].split('value=\"')[1].split('\"')[0] | |
# ausprobieren 'minorEdit': 'true', | |
params = urllib.urlencode({ | |
'atl_token':tokenId, | |
'originalVersion':version, | |
'conflictingVersion':version, | |
'title':title, | |
'content':content, | |
'newSpaceKey':spaceKey | |
}) | |
f = urllib2.urlopen(link, params) | |
c = f.read() | |
# o = open('out.txt','w') | |
# o.write(c) | |
if 'errorMessage error' in c: | |
print 'No errors' | |
else: | |
errorMessage = c.split("errorMessage\">")[1].split('</span>')[0].strip() | |
print 'ERROR' | |
print errorMessage | |
def pushFile(self, filename): | |
content = open(filename,'r').read() | |
self.pushText(self.url,self.username,self.password,self.spaceKey,self.baseId, self.tokenId, content) | |
content = 'Test ....' | |
if __name__ == "__main__": | |
# content = sys.argv[1] | |
f = 'test.md' | |
# CHANGE THESE | |
url = 'https://some.confluence.site/' | |
username = 'john_doe' | |
password = 'xxx' | |
baseId = '29269755' | |
tokenId = 'abcdefg' | |
p = Pusher(url, username, password, baseId) | |
p.pushFile(f) | |
push(url,username,password,spaceKey,baseId, tokenId, content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment