1
#quick google hack by liedra at liedra dot net
2
#can't work out why it's saying it's not callable but it seems to work anyway :)
3
#released under the BSD License (c) 2009 C. Flick
4
5
do_google_command = {'description': "Google search for something",
6
                  'long help': """\
7
Google searches for something.""",
8
                  'arguments':
9
                      [("<query>", "Searches google for <query>")],
10
                  'public': True,
11
                  'level': 0}
12
13
14
import urllib
15
import simplejson
16
import re
17
18
19
20
def do_google(self, server, sender, target, args):
21
	if not args:
22
		self.respond(server, sender, target, "Not enough arguments.")
23
		return
24
	query = ''.join(args)
25
	query = urllib.urlencode({'q' : query})
26
	url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % (query)
27
	search_results = urllib.urlopen(url)
28
	json = simplejson.loads(search_results.read())
29
	results = json['responseData']['results']
30
	for i in range(0,2):
31
		title = re.compile(r'<.*?>').sub('', results[i]['title'])
32
		url = re.compile(r'<.*?>').sub('', results[i]['url'])
33
		self.respond(server, sender, target, title + ': '+ url)
34
	return True
35