diff --git a/plugins/hackernews.py b/plugins/hackernews.py new file mode 100644 index 0000000..1b53167 --- /dev/null +++ b/plugins/hackernews.py @@ -0,0 +1,14 @@ +from util import http, hook + + +@hook.regex(r'(?i)https://(?:www\.)?news\.ycombinator\.com\S*id=(\d+)') +def hackernews(match): + base_api = 'https://hacker-news.firebaseio.com/v0/item/' + entry = http.get_json(base_api + match.group(1) + ".json") + + 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) +