Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 829 Bytes

README.md

File metadata and controls

32 lines (21 loc) · 829 Bytes

Hacker News recently released an official API. Unfortunately, it cannot be used to get the newest posts submitted. This script provides a faux streaming-api like method to indefinitely yield new hacker news submissions.

Can be useful if you want to create cusotm alerts (like email notifications or gtk notifications) with a simple script.

pip install lxml ujson requests

Usage

from hn import HNStream

h = HNStream()

for item in h.submission_stream():
    if 'python' in item['title'].lower():
        # trigger a custom alert you've written
        send_email(subject="Python post!", body="<a href='{}'>Link!</a>".format(item['url']))

Or if you want to listen for comments

for comment in h.comment_stream():
    if comment['by'] == 'tptacek':
        print (comment['text'])