-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_analytics.py
37 lines (31 loc) · 1.04 KB
/
add_analytics.py
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
36
37
import os
analytics = ''
with open('_includes/analytics.html', 'r', encoding='utf-8-sig') as org:
analytics = org.readlines()
def test(filename):
if filename.find('.htm') < 0:
return False
with open(filename, 'r', encoding='utf-8-sig') as md:
for line in md:
if line.find('</head>') > -1 and line.find('<!-- analytics -->') < 0:
return True
return False
def inc(filename):
text = ''
with open(filename, 'r', encoding='utf-8-sig') as md:
text = md.readlines()
with open(filename, 'w', encoding='utf-8-sig') as md:
for line in text:
if line.find('</head>') > -1 and line.find('<!-- analytics -->') < 0:
md.writelines(analytics)
md.write('<!-- analytics -->')
md.write(line)
def scan(path):
for root, folder, name in os.walk(path):
for file in name:
full = os.path.join(root, file)
if test(full):
print(full)
inc(full)
scan('mql5')
scan('java')