Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a Python script that used XML/RPC to find those macros, remove them, and save the pages

kaushal November 6, 2014

How to run a Python script that used XML/RPC to find those macros, remove them, and save the pages.

1 answer

0 votes
Jonathan Simonoff
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2014

Here's a program that is pretty close to what you need.  Your wiki needs to be open to XML/RPC access, you need to put in credentials and the right URL, and you need to put in the text you need to remove. If what you want to remove a macro that varies because of different parameters, you'll need to use re (the Python regex module) rather than doing a string replace.

Note that this acts on the storage format – to see what your macro looks like in storage format, choose Tools > View Storage Format when looking at a page that has the macro.

If you want to go through the entire wiki, you can get the space list using the XML/RPC method "getSpaces" and add an additional for loop to go through the spaces.

 

#!/usr/bin/python
#
import re,sys
from xmlrpclib import Server
space='Linux'
comment={'versionComment':"Page put into format by script."}
# main program
# Set up confluence
s=Server("http://serverbaseurl/rpc/xmlrpc")
token=s.confluence2.login("username","password")
pages=s.confluence2.getPages(token,space)
for pagesum in pages:
  pagename=pagesum['title']
  try:
    page=s.confluence2.getPage(token,space,pagename)
    print "Doing page",pagename.encode('utf8','replace')
  except:
    print "Couldn't read page",pagename
    continue
  page['content']=model['content'].replace('remove','')
  page=s.confluence2.updatePage(token,page,comment)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events