Newer
Older
# Copyright 2010, 2011 G24
#
# This file is part of gpy.
#
# gpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gpy. If not, see <http://www.gnu.org/licenses/>.
import main
import urllib
import json
class mod_main(main.clisten):
"""Web module."""
def addcmds(self):
self.name = "web"
self.cmds = {"ddg":"ddg"}
def ddg(self):
'''www.duckduckgo.com web search.'''
try:
request = self.conn.recvinfo["message.params"].replace(" ","+")
sock = urllib.urlopen("http://api.duckduckgo.com/?q=%s&o=json"%request)
data = sock.read()
sock.close()
if json.loads(data)["AbstractText"]!="":
self.conn.reply("In %s `%s`: %s... ( %s )"%(json.loads(data)["AbstractSource"].encode('utf-8'),json.loads(data)["Heading"].encode('utf-8'),json.loads(data)["AbstractText"].encode('utf-8')[0:200],json.loads(data)["AbstractURL"].encode('utf-8')))
elif json.loads(data)["Definition"] != "":
self.conn.reply("In %s: %s... ( %s )"%(json.loads(data)["DefinitionSource"].encode('utf-8'),json.loads(data)["Definition"].encode('utf-8'),json.loads(data)["DefinitionURL"].encode('utf-8')))
except Exception, e:
self.conn.reply(str(e))