From 037041cae40c77148c1f51d02e6c5e96386d46b2 Mon Sep 17 00:00:00 2001 From: Michael Barnes Date: Wed, 25 Apr 2012 19:47:40 -0400 Subject: [PATCH] added the cat facts command --- modules/catfacts.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 modules/catfacts.py diff --git a/modules/catfacts.py b/modules/catfacts.py new file mode 100644 index 0000000..71cad53 --- /dev/null +++ b/modules/catfacts.py @@ -0,0 +1,25 @@ +#!/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: + return fact['factoid'] + except IndexError: + return None + except TypeError: + print(fact) + return False + +def catfacts(phenny, input): + fact = catfacts_get() + if fact: + phenny.reply(fact) +catfacts.commands = ['catfacts'] +catfacts.priority = 'high'