DDG/FML/Isup: work towards PEP8 compliancy

Skipping the config options in config.py since the indented version
looks just as bad (not enough space to write the text without making
it use 5 lines).
This commit is contained in:
James Lu 2014-12-27 11:37:16 -08:00
parent dd0493ddb2
commit 4a62b4ad13
9 changed files with 38 additions and 24 deletions

View File

@ -38,6 +38,7 @@ except:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
def configure(advanced): def configure(advanced):
# This will be called by supybot to configure this module. advanced is # This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified themself as an advanced # a bool that specifies whether the user identified themself as an advanced

View File

@ -41,6 +41,7 @@ except ImportError:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
try: # Python 3 try: # Python 3
from urllib.parse import urlencode from urllib.parse import urlencode
except ImportError: # Python 2 except ImportError: # Python 2
@ -49,8 +50,9 @@ try:
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
except ImportError: except ImportError:
raise ImportError("Beautiful Soup 4 is required for this plugin: get it" raise ImportError("Beautiful Soup 4 is required for this plugin: get it"
" at http://www.crummy.com/software/BeautifulSoup/bs4/doc/" " at http://www.crummy.com/software/BeautifulSoup/bs4"
"#installing-beautiful-soup") "/doc/#installing-beautiful-soup")
class DDG(callbacks.Plugin): class DDG(callbacks.Plugin):
"""Searches for results on DuckDuckGo.""" """Searches for results on DuckDuckGo."""
@ -75,7 +77,8 @@ class DDG(callbacks.Plugin):
continue continue
try: try:
# 1) Get a result snippet. # 1) Get a result snippet.
snippet = res.parent.next_sibling.next_sibling.find_all("td")[-1] snippet = res.parent.next_sibling.next_sibling.\
find_all("td")[-1]
# 2) Fetch the result link. # 2) Fetch the result link.
link = res.a.get('href') link = res.a.get('href')
snippet = snippet.text.strip() snippet = snippet.text.strip()

View File

@ -30,11 +30,13 @@
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('ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/') self.assertRegexp(
'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/')
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -38,6 +38,7 @@ except:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
def configure(advanced): def configure(advanced):
# This will be called by supybot to configure this module. advanced is # This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified themself as an advanced # a bool that specifies whether the user identified themself as an advanced

View File

@ -43,6 +43,7 @@ except ImportError:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
class FML(callbacks.Plugin): class FML(callbacks.Plugin):
"""Displays entries from fmylife.com.""" """Displays entries from fmylife.com."""
threaded = True threaded = True
@ -51,7 +52,8 @@ class FML(callbacks.Plugin):
"""requires no arguments. """requires no arguments.
Displays a random entry from fmylife.com.""" Displays a random entry from fmylife.com."""
url = 'http://api.betacie.com/view/random?key=4be9c43fc03fe&language=en' url = ('http://api.betacie.com/view/random?key=4be9c43fc03fe'
'&language=en')
try: try:
data = utils.web.getUrl(url) data = utils.web.getUrl(url)
except utils.web.Error as e: except utils.web.Error as e:
@ -63,8 +65,9 @@ class FML(callbacks.Plugin):
text = tree.find('text').text text = tree.find('text').text
fmlid = tree.attrib['id'] fmlid = tree.attrib['id']
url = tree.find('short_url').text url = tree.find('short_url').text
votes = ircutils.bold("[Agreed: %s / Deserved: %s]" % \ votes = ircutils.bold("[Agreed: %s / Deserved: %s]" %
(tree.find('agree').text, tree.find('deserved').text)) (tree.find('agree').text,
tree.find('deserved').text))
s = format('\x02#%i [%s]\x02: %s - %s %u', fmlid, s = format('\x02#%i [%s]\x02: %s - %s %u', fmlid,
category, text, votes, url) category, text, votes, url)
irc.reply(s) irc.reply(s)

View File

@ -30,6 +30,7 @@
from supybot.test import * from supybot.test import *
class FMLTestCase(PluginTestCase): class FMLTestCase(PluginTestCase):
plugins = ('FML',) plugins = ('FML',)

View File

@ -41,6 +41,7 @@ except ImportError:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
class Isup(callbacks.Plugin): class Isup(callbacks.Plugin):
"""Provides a simple command to check whether a website is up """Provides a simple command to check whether a website is up
or down (using isup.me).""" or down (using isup.me)."""
@ -54,7 +55,8 @@ class Isup(callbacks.Plugin):
elif "doesn't look like a site" in data: elif "doesn't look like a site" in data:
reply = 'unknown' reply = 'unknown'
elif "and still think we're down" in data: elif "and still think we're down" in data:
return "Haven't you got anything better to do than look for hidden special replies? :P" return ("Haven't you got anything better to do than look for "
"hidden special replies? :P")
else: else:
return "An error occurred, please check your URL and try again." return "An error occurred, please check your URL and try again."
try: try:

View File

@ -30,6 +30,7 @@
from supybot.test import * from supybot.test import *
class IsupTestCase(PluginTestCase): class IsupTestCase(PluginTestCase):
plugins = ('Isup',) plugins = ('Isup',)