Merge pull request #134 from Ell/master
Added support for retrieving information from hackernews urls
This commit is contained in:
commit
a3e1b452e7
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue