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

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

1 answer

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

110 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you