From 5b6ac8b85168d08a6bdb8c94fd7001de280d9f57 Mon Sep 17 00:00:00 2001 From: Max Gurela Date: Thu, 19 Feb 2015 22:18:08 -0500 Subject: [PATCH] Add hummingbird support --- hummingbird.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 hummingbird.py diff --git a/hummingbird.py b/hummingbird.py new file mode 100644 index 0000000000..9030bf6f03 --- /dev/null +++ b/hummingbird.py @@ -0,0 +1,48 @@ +# coding=utf8 +""" +hummingbird.py - You have no life. +Copyright 2015 Max Gurela + +Licensed under the Eiffel Forum License 2. +""" + +from willie.module import commands,rule,example +from willie.formatting import color +from willie import web +from datetime import datetime, timedelta +import json + + +@commands('hb','hummingbird') +@example('.hummingbird maxpowa') +def hummingbird(bot, trigger): + """ + .hummingbird [user] - Show information on a Hummingbird user + """ + data = trigger.group(2) + + if not data: + data = trigger.nick + + format_user(bot, data) + + +def format_user(bot, user): + url = 'https://hummingbird.me/api/v1/users/{}'.format(user) + raw = web.get(url) + try: + data = json.loads(raw) + except: + return bot.say('[Hummingbird] User does not exist.') + + if 'error' in data: + return bot.say(u'[Hummingbird] '+data['error']) + + output = '[Hummingbird] {name} | {website} | {about} | {life_wasted}' + + data['about'] = data['about'].strip() + h, m = divmod(int(data['life_spent_on_anime']), 60) + d, h = divmod(h, 24) + data['life_wasted'] = '{} days, {} hours, {} minutes spent watching anime'.format(d,h,m) + + bot.say(output.format(**data))