Merge remote-tracking branch 'upstream/develop' into develop

This commit is contained in:
Fletcher Boyd 2013-09-05 12:04:47 +08:00
commit 00e3fb2dc1

26
plugins/osrc.py Normal file
View file

@ -0,0 +1,26 @@
from util import hook, http, web
from bs4 import BeautifulSoup
api_url = "http://osrc.dfm.io/{}/stats"
@hook.command
def osrc(inp):
"""osrc <github user> -- Gets an Open Source Report Card for <github user>"""
user_nick = inp.strip()
url = api_url.format(user_nick)
try:
response = http.get_json(url)
except (http.HTTPError, http.URLError):
return "Couldn't find any stats for this user."
response["nick"] = user_nick
soup = BeautifulSoup(response["summary"])
response["work_time"] = soup.find("a", {"href" : "#day"}).contents[0]
response["short_url"] = web.try_isgd(url)
return "{nick} is a {lang_user}. {nick} is a {hacker_type} " \
"who seems to {work_time} - {short_url}".format(**response)