phenny-1/modules/catfacts.py

27 lines
556 B
Python
Raw Normal View History

2012-04-25 19:47:40 -04:00
#!/usr/bin/env python
import web
def catfacts_ajax():
uri = 'http://facts.cat/getfact'
bytes = web.get(uri)
return web.json(bytes)
def catfacts_get():
fact = catfacts_ajax()
try:
2012-05-01 23:52:19 -04:00
return "{0} (#{1:d})".format(fact['factoid'], fact['id'])
2012-04-25 19:47:40 -04:00
except IndexError:
return None
except TypeError:
print(fact)
return False
def catfacts(phenny, input):
2013-10-05 19:20:37 -04:00
""".catfact - Receive a cat fact."""
2012-04-25 19:47:40 -04:00
fact = catfacts_get()
if fact:
phenny.reply(fact)
2013-10-05 19:20:37 -04:00
catfacts.commands = ['catfact', 'catfacts']