Modify iWeb sites to work with Google Analytics

wanted to use Google Analytics together with iWeb & didn’t want to use BBEdit, someEdit, someOtherEdit or an Automator action… as i have to sync the iWeb content anyway - why not use a little (python) script to integrate the Google snippet?

use somthing like

find iWeb/ -iname ‘*.html’ -exec ./iWeb.py “” iWeb.analytics {} {} \;

with iWeb.analytics beeing the Google snippet and iWeb.py the follwoing script. after that i use sitecopy –update [SITENAME]…

#!/usr/bin/env python
import sys,os
usage = “usage: %s searchText insertText_file [infile [outfile]]” % os.path.basename(sys.argv[0])

def init():

stext = sys.argv[1]

replaceTextFileIn = open(sys.argv[2],‘r’)
replaceTextFileContent = replaceTextFileIn.readlines()
replaceTextFileIn.close()

# print replaceTextFileContent

input = sys.stdin
output = sys.stdout
if len(sys.argv) > 3:
input = open(sys.argv[3])

inputContent = input.readlines()
input.close()

if len(sys.argv) > 4:
output = open(sys.argv[4], ‘w’)

for s in inputContent:
output.write(s.replace(stext, ‘'.join(replaceTextFileContent) + stext))

output.close()

if __name__ == “__main__":
if len(sys.argv)

the latest version of this script might be available from (something like):
https: / / iiegn.dyndns.org / svn / de.iiegn / _stuff / iWeb.py

references:

  1. http://www.macosxhints.com/article.php?story=20061220033306772

  2. http://www.apple.com/downloads/macosx/automator/addgoogleanalyticsaction.html

  3. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52250

Next
Previous

Related