Skip to content

Instantly share code, notes, and snippets.

@rm
Last active January 4, 2016 02:59
Show Gist options
  • Select an option

  • Save rm/8558781 to your computer and use it in GitHub Desktop.

Select an option

Save rm/8558781 to your computer and use it in GitHub Desktop.
Convert colloquy transcripts to HTML. You might need to change the variables RESOURCE_DIR, XSLT_FILE and CSS_FILE. I save the file as colloquy-transform in ~/bin/ and chmod 0755 it.
#!/usr/bin/env python
# -*- mode: python; backup-inhibited: t -*-
import glob
import os
import re
import subprocess
import sys
RESOURCE_DIR = ('/Users/roshan/Library/Application Support/Colloquy/'
'Styles/Succinct.colloquyStyle/Contents/Resources')
XSLT_FILE = os.path.join(RESOURCE_DIR, 'main.xsl')
CSS_FILE = os.path.join(RESOURCE_DIR, 'main.css')
def usage(error=None):
print >>sys.stderr, 'Usage: %s <input-dir> <output-dir>'
print >>sys.stderr, ' convert each .colloquyTranscript file to .html'
if error:
print >>sys.stderr, 'Error: %s' % error
sys.exit()
def main():
if len(sys.argv) != 3:
usage('Missing arguments')
input_dir = sys.argv[1]
output_dir = sys.argv[2]
if not os.path.exists(input_dir) or not os.path.isdir(input_dir):
usage('input directory not found "%s"' % input_dir)
if not os.path.exists(output_dir) or not os.path.isdir(output_dir):
usage('output directory not found "%s"' % output_dir)
input_matcher = re.compile('#(\S+) (\d\d)-(\d\d)-(\d\d).colloquyTranscript')
for ifile in glob.glob(os.path.join(input_dir, '*.colloquyTranscript')):
print 'Converting "%s"' % os.path.basename(ifile)
chunks = input_matcher.search(ifile).groups()
ofile = '%s-20%s%s%s.html' % (chunks[:1] + tuple(reversed(chunks[1:])))
output = file(ofile, 'w')
output.write('<link rel="stylesheet" type="text/css" href="%s">' %
CSS_FILE)
output.flush()
output.close()
subprocess.call('xsltproc "%s" "%s" >>"%s"' % (XSLT_FILE, ifile, ofile),
shell=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment