-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddGA
executable file
·35 lines (30 loc) · 1.08 KB
/
addGA
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
#! /usr/bin/env python
import subprocess
p = subprocess.Popen(["find", "-type", "f", "-name", "*.html"], stdout=subprocess.PIPE)
out, err = p.communicate()
GA = """
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-38388212-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
"""
for file in out.split('\n'):
file = file.strip()
if file != '':
f = open(file, 'r')
contents = f.read()
f.close()
where = contents.find('UA-38388212-1')
if where == -1:
where = contents.find('</head>')
if where != -1:
f = open(file, 'w')
newcontents = contents[0:where - 1] + GA + contents[where:]
f.write(newcontents)
f.close()