forked from sopel-irc/sopel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |