forked from jbruechert/freetz.org
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate-searchform.py
More file actions
executable file
·34 lines (25 loc) · 934 Bytes
/
update-searchform.py
File metadata and controls
executable file
·34 lines (25 loc) · 934 Bytes
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
#!/usr/bin/env python3
'''
Find all HTML pages with the default Trac search field, and replace them with Google code
'''
import re
import sys
oldform = '\n\s*<form id="search".*?</form>\n'
newform = '''
<form id="search" action="https://www.google.com/search" method="get" onsubmit="; this.elements.namedItem('q').value = this.elements.namedItem('oq').value + ' site:freetz.github.io'">
<div>
<label for="proj-search">Suche:</label>
<input type="text" id="proj-search" name="oq" size="18" value="" />
<input type="hidden" name="q" value="" />
<input type="submit" value="Suche" />
</div>
</form>
'''
def replaceSearchForm(name):
with open(name, encoding='utf-8') as f:
s = f.read()
s = re.sub(oldform, newform, s, flags=re.S)
with open(name, encoding='utf-8', mode='w') as f:
f.write(s)
for n in sys.argv:
replaceSearchForm(n)