1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
script = \
"""
<!-- Generate pageview statistics when this document is viewed on the mpmath website -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
if ((""+document.location).match("google"))
{
_uacct = "UA-2697185-2";
urchinTracker();
}
</script>
"""
tag = "Generate pageview statistics"
import os
import os.path
paths = ["build", "build/functions", "build/calculus"]
for path in paths:
for fname in os.listdir(path):
if fname.endswith(".html"):
f = open(os.path.join(path, fname), "r+w")
if script not in f.read():
f.seek(0)
lines = f.readlines()
for i, l in enumerate(lines):
if "</body>" in l:
break
lines.insert(i, script)
f.seek(0)
f.write("".join(lines))
print "modified", fname
|