Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a Google plugin.

  • Loading branch information...
commit 59498aaa491351a9534dc2c25e2e214b60465c0d 1 parent 3670fce
@titegtnodI authored
Showing with 23 additions and 1 deletion.
  1. +2 −1  main.py
  2. +21 −0 plugins/google.py
View
3  main.py
@@ -10,7 +10,8 @@
#These will be loaded from protoFolder and plugFolder respectively.
protoList = ['irc.py'] #Protocols to be loaded
-plugList = ['say.py', 'pyexec.py', 'irc_commands.py', 'time.py'] #Plugins to be loaded
+plugList = ['say.py', 'pyexec.py', 'irc_commands.py', 'ircop_commands.py', 'time.py',
+ 'google.py'] #Plugins to be loaded
protoFolder = 'protocols/'
plugFolder = 'plugins/'
View
21 plugins/google.py
@@ -0,0 +1,21 @@
+from json import loads
+from urllib2 import urlopen
+from urllib import urlencode
+plugName = 'Google Plugin'
+
+#TODO Descriptions
+
+def google_search(query, method):
+ return loads(urlopen('http://ajax.googleapis.com/ajax/services/search/'+method+'?v=1.0&'+
+ urlencode({'q':query})).read())
+
+def google_firstResult(inMSG, method):
+ result = google_search(inMSG[0].split(None, 1)[1], method)['responseData']['results']
+ if result:
+ sendMSG((result[0]['titleNoFormatting'] + ' -- ' + result[0]['unescapedUrl']).encode('utf-8'),
+ inMSG[1], inMSG[2], inMSG[3])
+ else:
+ sendMSG('No results found.', inMSG[1], inMSG[2], inMSG[3])
+
+def load():
+ return {'g':(lambda x: google_firstResult(x, 'web')), 'gi':(lambda x: google_firstResult(x, 'images'))}
Please sign in to comment.
Something went wrong with that request. Please try again.