2015-07-24 01:01:33 +00:00
|
|
|
from util import http, hook
|
|
|
|
|
|
|
|
|
2015-07-24 02:41:30 +00:00
|
|
|
@hook.regex(r'(?i)https://(?:www\.)?news\.ycombinator\.com\S*id=(\d+)')
|
2015-07-24 01:01:33 +00:00
|
|
|
def hackernews(match):
|
2015-07-24 02:41:30 +00:00
|
|
|
base_api = 'https://hacker-news.firebaseio.com/v0/item/'
|
|
|
|
entry = http.get_json(base_api + match.group(1) + ".json")
|
2015-07-24 01:01:33 +00:00
|
|
|
|
|
|
|
if entry['type'] == "story":
|
|
|
|
return "{title} by {by} with {score} points and {descendants} comments ({url})".format(**entry)
|
|
|
|
|
|
|
|
if entry['type'] == "comment":
|
|
|
|
return '"{text}" -- {by}'.format(**entry)
|
|
|
|
|