#!/usr/bin/python # #utility to remove 'activity' from .html files and replace with horizontal rule tag from path import path import os, sys, subprocess from optparse import OptionParser SOURCE = path('../') parser = OptionParser(usage="Usage: %prog [options] file") (options, args) = parser.parse_args() if not args: print 'Specify a course and milestone, e.g. zs5 zs5m08' parser.print_help() sys.exit(1) SUBJECT = args[0] COURSE = args[1] MILESTONE = args[2] tag = '
' basepath = SOURCE / SUBJECT / COURSE / MILESTONE files = basepath.files('*.html') file = files[0] fin = open(basepath / file.name,'r') txt = fin.read() fin.close() pos = txt.find('Activity') count = 0 while pos > -1: pos1 = txt.find('
') pos2 = txt.find('
') if pos1 < 0 or pos2 < 0: pos = -1 continue if count < 1: txt = txt[:pos1]+txt[pos2+9:] else: txt = txt[:pos1] + '
' + txt[pos2+9:] count += 1 pos = txt.find('Activity') print count, pos, len(txt) fout = open(basepath / MILESTONE+'.html','w') fout.write(txt) fout.close