Created
August 2, 2014 17:03
-
-
Save hdf/c4ada7686f6674a0a9c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys, re | |
dir = 'files' | |
if len(sys.argv) > 1: | |
dir = sys.argv[1] | |
trackingcode = """\g<1> | |
<a title="Web Analytics" href="http://clicky.com/100759434"><img alt="Web Analytics" src="//static.getclicky.com/media/links/badge.gif" border="0" /></a> | |
<script src="//static.getclicky.com/js" type="text/javascript"></script> | |
<script type="text/javascript">try{ clicky.init(100759434); }catch(e){}</script> | |
<noscript><p><img alt="Clicky" width="1" height="1" src="//in.getclicky.com/100759434ns.gif" /></p></noscript> | |
\g<2>""" | |
pattern = re.compile("(<!--end\ footer-->).*(<\/body>)", re.I | re.M | re.S) | |
for root, subFolders, files in os.walk(dir): | |
for file in files: | |
if re.search('\.htm|\.html', file): | |
filename = os.path.join(root, file) | |
f = open(filename, 'r+') | |
s = f.read() | |
f.seek(0) | |
f.write(pattern.sub(trackingcode, s)) | |
f.truncate() | |
f.close() | |
print filename + " updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment