from dircache import listdir
from stat import *
from os import chdir, stat, path
from string import split
import re
import sys

filedir = '.'

if sys.argv[1:]:
	filedir = sys.argv[1]

d = listdir( filedir )


for i in d:
    #print i
    i = path.join(filedir, i)
    if (not S_ISDIR( stat(i).st_mode )) and i[-5:] == '.html':
	print "Processing: ",i
        infile = open ( i );
        buffer = infile.read();
        infile.close()
        #
        buf2 = re.sub( r'\<body\>', r'<body onLoad="DoIt()">', buffer )
        buffer = re.sub( r'\</head\>', r'<script type="text/javascript" src="/scripts/banner.js"></script></head>', buf2 )
        buf2 = re.sub( r'\<div id="ads"\>\<\/div\>', r'<div align="center" id="ads"><iframe marginheight="0" marginwidth="0" name="ads" frameborder="0" width="468" height="60">banner</iframe></div>', buffer )
        outfile = open( i, 'w' )
        outfile.write( buf2 )
        outfile.close()