diff --git a/plugins/osrc.py b/plugins/osrc.py index 7df2085..99cba1c 100644 --- a/plugins/osrc.py +++ b/plugins/osrc.py @@ -3,7 +3,6 @@ from bs4 import BeautifulSoup from util import hook, http, web -api_url = "http://osrc.dfm.io/{}/stats" user_url = "http://osrc.dfm.io/{}" @@ -12,18 +11,19 @@ def osrc(inp): """osrc -- Gets an Open Source Report Card for """ user_nick = inp.strip() - url = api_url.format(user_nick) + url = user_url.format(user_nick) try: - response = http.get_json(url) + soup = http.get_soup(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] + report = soup.find("div", {"id": "description"}).find("p").get_text() - response["short_url"] = web.try_isgd(user_url.format(user_nick)) + # Split and join to remove all the excess whitespace, slice the + # string to remove the trailing full stop. + report = " ".join(report.split())[:-1] - return "{nick} is a {lang_user}. {nick} is a {hacker_type} " \ - "who seems to {work_time} - {short_url}".format(**response) + short_url = web.try_isgd(url) + + return "{} - {}".format(report, short_url) diff --git a/plugins/suggest.py b/plugins/suggest.py index 6fd4fdd..0e02210 100644 --- a/plugins/suggest.py +++ b/plugins/suggest.py @@ -24,6 +24,4 @@ def suggest(inp): soup = BeautifulSoup(out) out = soup.get_text() - out = text.truncate_str(out, 200) - - return out + return text.truncate_str(out, 200) diff --git a/util/text.py b/util/text.py index 3fd679a..e3604dc 100644 --- a/util/text.py +++ b/util/text.py @@ -144,7 +144,9 @@ def truncate_words(content, length=10, suffix='...'): # from def truncate_str(content, length=100, suffix='...'): - """Truncates a string after a certain number of chars.""" + """Truncates a string after a certain number of chars. + @rtype : str + """ if len(content) <= length: return content else: