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

This widget could not be displayed.

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
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

445 views 5 6
Join discussion

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