Edgewall Software

MacroBazaar: Search.py

File Search.py, 709 bytes (added by Muness Alrubaie <muness@…>, 7 years ago)

Search macro

Line 
1"""
2Build a search URL for the supplied argument or just a link to a search
3engine if no args are present.
4
5Defaults to google.  Edit the macro to modify the engine(/url).
6
7This script doesn't encode the search string provided.  Seems to work fine
8on IE 6 and FireFox 1.0.
9"""
10
11searchurl_prefix="http://www.google.com/search?hl=en&q="
12searchurl="http://www.google.com/"
13
14from StringIO import StringIO
15
16def execute(hdf, args, env):
17
18  url= None
19  link= None
20  if args:
21      text = args
22      url = searchurl_prefix + args
23  else:
24      text = "Search"
25      url = searchurl
26
27  buf = StringIO()
28  buf.write('<a title="Search" href="%s">' % url)
29  buf.write(text)
30  buf.write('</a>\n')
31
32  return buf.getvalue()