Close this search box.

Script Time: convert a Second Life chatlog to Confluence Wiki Markup with Python (Technical)

Today we had yet another meetup of the DataPortability Group in Second Life and we mainly discussed why discussing ownership brings us nowhere. Instead Steve Greenberg, who joined us talks about his view on rules on usage and licenses instead of using the term „ownership“.

As this was quite interesting I am putting up the transcript now (you can find it here). To do this I wrote a small script which converts the chatlog format of Second Life to a wiki syntax for Confluence wikis as you can see in the link above.

Attached is the script in case you might have a need for it.

The features:

  • makes the chatlog more readable by using Confluence wiki markup
  • replaces „You“ in the chatlog by a name you give on the command line
  • gives each avatar name a different color to quickly see who’s talking
#!/usr/bin/env python


convert a Second Life chatlog with timestamps to a wiki markup as used by confluence

Copyright 2008 by Christian 'MrTopf' Scholz,

released under the GPL:


import sys, re
from optparse import OptionParser

EXP = re.compile("^\[(..:..)\]  ((?:You)|([\w]+ [\w]+)): (.+?)(?=\n\[)",re.M|re.S)

explanation of the regexp:

^ will match the start of a line
\[..:..\] will match the time stamp
([\w]+(?: [\w]+)?) matches One or two part names (You and a firstname lastname combination) or use:
((?:You)|([\w]+ [\w]+)) matches "You" or a name
(.+?) matches anything not greedy
(?=\n\[) means that the match before will only be made until a \n followed by [ appears which is a new timestamp
and the beginning of a new match.


USAGE="""%prog <filename> -o <outfile> -n <avname>

filename: the filename of the chatlog
outfile: output file, if not given it will be written to stdout
avname: if given will replace "You" in the chatlog with this avatar name (e.g. your name if you recorded it)


def main():
    parser = OptionParser(USAGE)
    parser.add_option("-o", "--outfile", dest="outfile",
                      help="output filename", metavar="FILE")
    parser.add_option("-n", "--avname", dest="avname",
                      help="your avatar nickname")

    (options, args) = parser.parse_args()

    # process arguments
    if len(args)!=1:
        parser.error("wrong number of arguments")
    filename = args[0]

    if options.outfile:
        outfp = open(options.outfile,"w")
        outfp = sys.stdout

    if options.avname:
        you = options.avname
        you = "You"

    data =
    colors=['#303080', '#a05000', '#a0a000', '#0080a0', '#00a050', 'red', 'blue']
    colorcounter = 0
    names = {}

    matches = EXP.findall(data) # let regexps do their magic

    for match in matches:
        time,name,dummy,text = match
        if name=="You":
                name = you
        if name not in names.keys():
            colorcounter = (colorcounter+1)%(len(colors))
        text = text.replace("\n"," ")

        outfp.write("(%s) {color:%s}+%s+{color}: %s\n" %(time,names[name],name,text))

if __name__=="__main__":

Technorati Tags: , , , , , , ,

Teile diesen Beitrag