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()

Svetlana Tkachenko
committed
if json.loads(data)["Definition"]!="":
self.conn.reply(json.loads(data)["Definition"])
except Exception, e:
self.conn.reply(str(e))