wiki: handle json parsing error
parent
2c9a937c2e
commit
6ecbe4ca18
|
@ -22,6 +22,14 @@ class TestArchwiki(unittest.TestCase):
|
||||||
out, flags=re.UNICODE)
|
out, flags=re.UNICODE)
|
||||||
self.assertTrue(m)
|
self.assertTrue(m)
|
||||||
|
|
||||||
|
def test_awik_invalid(self):
|
||||||
|
term = "KVM#Enabling_KSM"
|
||||||
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
archwiki.awik(self.phenny, input)
|
||||||
|
|
||||||
|
self.phenny.say.assert_called_once_with( "Can't find anything in "\
|
||||||
|
"the ArchWiki for \"{0}\".".format(term))
|
||||||
|
|
||||||
def test_awik_none(self):
|
def test_awik_none(self):
|
||||||
term = "Ajgoajh"
|
term = "Ajgoajh"
|
||||||
input = Mock(groups=lambda: ['', term])
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
|
|
@ -22,6 +22,14 @@ class TestVtluugwiki(unittest.TestCase):
|
||||||
out, flags=re.UNICODE)
|
out, flags=re.UNICODE)
|
||||||
self.assertTrue(m)
|
self.assertTrue(m)
|
||||||
|
|
||||||
|
def test_vtluug_invalid(self):
|
||||||
|
term = "EAP-TLS#netcfg"
|
||||||
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
vtluugwiki.vtluug(self.phenny, input)
|
||||||
|
|
||||||
|
self.phenny.say.assert_called_once_with( "Can't find anything in "\
|
||||||
|
"the VTLUUG Wiki for \"{0}\".".format(term))
|
||||||
|
|
||||||
def test_vtluug_none(self):
|
def test_vtluug_none(self):
|
||||||
term = "Ajgoajh"
|
term = "Ajgoajh"
|
||||||
input = Mock(groups=lambda: ['', term])
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
|
|
@ -22,6 +22,14 @@ class TestWikipedia(unittest.TestCase):
|
||||||
out, flags=re.UNICODE)
|
out, flags=re.UNICODE)
|
||||||
self.assertTrue(m)
|
self.assertTrue(m)
|
||||||
|
|
||||||
|
def test_wik_invalid(self):
|
||||||
|
term = "New York City#Climate"
|
||||||
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
wikipedia.wik(self.phenny, input)
|
||||||
|
|
||||||
|
self.phenny.say.assert_called_once_with( "Can't find anything in "\
|
||||||
|
"Wikipedia for \"{0}\".".format(term))
|
||||||
|
|
||||||
def test_wik_none(self):
|
def test_wik_none(self):
|
||||||
term = "Ajgoajh"
|
term = "Ajgoajh"
|
||||||
input = Mock(groups=lambda: ['', term])
|
input = Mock(groups=lambda: ['', term])
|
||||||
|
|
3
wiki.py
3
wiki.py
|
@ -43,10 +43,13 @@ class Wiki(object):
|
||||||
def search(self, term, last=False):
|
def search(self, term, last=False):
|
||||||
url = self.api.format(term)
|
url = self.api.format(term)
|
||||||
bytes = web.get(url)
|
bytes = web.get(url)
|
||||||
|
try:
|
||||||
result = json.loads(bytes)
|
result = json.loads(bytes)
|
||||||
result = result['query']['search']
|
result = result['query']['search']
|
||||||
if len(result) <= 0:
|
if len(result) <= 0:
|
||||||
return None
|
return None
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
term = result[0]['title']
|
term = result[0]['title']
|
||||||
term = term.replace(' ', '_')
|
term = term.replace(' ', '_')
|
||||||
snippet = self.text(result[0]['snippet'])
|
snippet = self.text(result[0]['snippet'])
|
||||||
|
|
Loading…
Reference in New Issue