-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathPoCEdit.py
44 lines (35 loc) · 954 Bytes
/
PoCEdit.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
38
39
40
41
42
43
44
"""
Author: Chen Zhang (demi6od) <[email protected]>
Date: 2013 Oct 21st
"""
#!/usr/bin/env python
import glob
import os
import sys
import time
import datetime
import re
import shutil
def pairBrace(fname):
htmlFile = open(fname, 'r+')
htmlSrc = htmlFile.read()
# Strip braces in string
htmlSrcStrip = re.sub(r'"[^"]*"', '', htmlSrc)
# Count brace delta
openBraceCnt = len(re.findall(r'\{', htmlSrcStrip))
closeBraceCnt = len(re.findall(r'\}', htmlSrcStrip))
delta = openBraceCnt - closeBraceCnt
# Pair delta braces
for i in range(0, delta):
htmlSrc = re.sub(r'</script> *\s* *</head>', '}</script>\n</head>', htmlSrc)
htmlFile.seek(0)
htmlFile.write(htmlSrc)
htmlFile.truncate()
htmlFile.close()
def main():
curDir = os.getcwd()
htmlList = glob.glob(curDir + '\\*.html')
for fname in htmlList:
pairBrace(fname)
if __name__ == "__main__":
main()