mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-12 21:22:36 +01:00
DDG: remove the 'zeroclick' command
The IRC output is poorly formatted, and doesn't yield useful results most of the time anyways.
From: cdf6c7eb3e
This commit is contained in:
parent
e4d16257b6
commit
c73542fb3f
37
plugin.py
37
plugin.py
@ -166,43 +166,6 @@ class DDG(callbacks.Plugin):
|
|||||||
|
|
||||||
irc.reply(', '.join(strings))
|
irc.reply(', '.join(strings))
|
||||||
|
|
||||||
@wrap(['text'])
|
|
||||||
def zeroclick(self, irc, msg, args, text):
|
|
||||||
"""<text>
|
|
||||||
|
|
||||||
Looks up <text> on DuckDuckGo's zero-click engine."""
|
|
||||||
# Zero-click can give multiple replies for things if the
|
|
||||||
# query is ambiguous, sort of like an encyclopedia.
|
|
||||||
|
|
||||||
# For example, looking up "2^3" will give both:
|
|
||||||
# Zero-click info: 8 (number)
|
|
||||||
# Zero-click info: 8
|
|
||||||
replies = {}
|
|
||||||
for td in self._ddgurl(text)[-1]:
|
|
||||||
if td.text.startswith("Zero-click info:"):
|
|
||||||
# Make a dictionary of things
|
|
||||||
item = td.text.split("Zero-click info:", 1)[1].strip()
|
|
||||||
td = td.parent.next_sibling.next_sibling.\
|
|
||||||
find("td")
|
|
||||||
# Condense newlines (<br> tags). XXX: make these separators configurable.
|
|
||||||
for br in td.find_all('br'):
|
|
||||||
br.replace_with(' - ')
|
|
||||||
res = ' | '.join(td.text.strip().split("\n"))
|
|
||||||
try:
|
|
||||||
# Some zero-click results have an attached link to them.
|
|
||||||
link = td.a.get('href')
|
|
||||||
# Others have a piece of meaningless JavaScript...
|
|
||||||
if link != "javascript:;":
|
|
||||||
res += format(" %u", link)
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
replies[item] = res
|
|
||||||
else:
|
|
||||||
if not replies:
|
|
||||||
irc.error("No zero-click info could be found for '%s'." %
|
|
||||||
text, Raise=True)
|
|
||||||
s = ["%s - %s" % (ircutils.bold(k), v) for k, v in replies.items()]
|
|
||||||
irc.reply("; ".join(s))
|
|
||||||
Class = DDG
|
Class = DDG
|
||||||
|
|
||||||
|
|
||||||
|
6
test.py
6
test.py
@ -1,5 +1,5 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2014-2015, James Lu
|
# Copyright (c) 2014-2017, James Lu <james@overdrivenetworks.com>
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -30,15 +30,11 @@
|
|||||||
|
|
||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
|
||||||
|
|
||||||
class DDGTestCase(PluginTestCase):
|
class DDGTestCase(PluginTestCase):
|
||||||
plugins = ('DDG',)
|
plugins = ('DDG',)
|
||||||
|
|
||||||
def testSearch(self):
|
def testSearch(self):
|
||||||
self.assertRegexp(
|
self.assertRegexp(
|
||||||
'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/')
|
'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/')
|
||||||
def testZeroclick(self):
|
|
||||||
self.assertRegexp(
|
|
||||||
'zeroclick 2^3', '8')
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
Reference in New Issue
Block a user