forked from Sunbird-Ed/SunbirdEd-portal
-
Notifications
You must be signed in to change notification settings - Fork 7
/
append.py
22 lines (20 loc) · 853 Bytes
/
append.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import sys
if len(sys.argv) == 3:
data = sys.argv[1] #data to append
filename = sys.argv[2] #input file name
if os.path.isfile(filename):
with open(filename,'r+') as f:
lines = f.readlines()
f.seek(0)
f.truncate()
for line in lines:
if "<link" in line:
line = line.replace('href="','href="'+data)
elif "<script" in line:
line = line.replace('src="','src="'+data)
f.write(line)
else:
print("inputfile "+filename+" not found")
else:
print("Please enter 2 argumets(data to append, input file name)")