Commit 16c3eed2 authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

not sure what i did to googlebot

parent 81d32471
......@@ -36,6 +36,8 @@ results = simplejson.load(response)
def search (t, userip='USERS-IP-ADDRESS', referer="http://automatist.net/"):
url = "https://ajax.googleapis.com/ajax/services/search/web"
if type(t) == unicode:
t = t.encode("utf-8")
url += "?" + urllib.urlencode({'v': '1.0', 'q': t, 'userip': userip})
request = urllib2.Request(url, None, {'Referer': referer})
return json.load(urllib2.urlopen(request))
......@@ -46,6 +48,7 @@ tos = {'lines': []}
with open("google_websearchtos.txt") as f:
start = True
for line in f:
line = line.decode("utf-8")
if start:
if ":" in line:
(name, value) = line.split(":", 1)
......@@ -64,6 +67,7 @@ class Bot(irc.bot.SingleServerIRCBot):
self.channel = channel
def on_welcome(self, c, e):
print "GOOGLEBOT is connected"
c.join(self.channel)
def on_privmsg(self, c, e):
......@@ -75,12 +79,12 @@ class Bot(irc.bot.SingleServerIRCBot):
if "google" in msg:
msg = msg.replace("google", "").strip()
results = search(msg)
c.privmsg(self.channel, 'Here are the first 3 search results for "{0}"...'.format(msg))
c.privmsg(self.channel, u'Here are the first 3 search results for "{0}"...'.format(msg))
for result in results['responseData']['results'][:3]:
resp = result['content'][:400].replace("\n", " ")
c.privmsg(self.channel, resp)
sleep(4)
msg = "( NB: From my terms of service: "+choice(tos['lines'])[:400]+")"
msg = u"NB: From my terms of service: "+choice(tos['lines'])[:400]
c.privmsg(self.channel, msg)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment