Merge pull request #134 from Ell/master

Added support for retrieving information from hackernews urls
This commit is contained in:
Ryan Hitchman 2015-07-23 19:53:08 -07:00
commit a3e1b452e7
1 changed files with 14 additions and 0 deletions

14
plugins/hackernews.py Normal file
View File

@ -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)