Search Hacker News with Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Search Hacker News with Python

from search_hn import SearchHN
hn = SearchHN()

String together methods to build queries

results = (hn
          .search('bitcoin')    # search query = 'bitcoin'
          .latest()             # return newest first
          .stories()            # stories only
          .get()                # execute search
for story in results: 
    print(story.title)          # each JSON result becomes object w/fields as attributes 
    author = story.get_author() # and helpers to get related items

Or just use the non-composable methods for quick results

>>> print(hn.get_latest_stories()[0])

{   '_tags': ['story', 'author_smacktoward', 'story_15383441'],
    'author': 'smacktoward',
    'title': 'Carrier Deployment Raises Questions About Navy’s Rash of '
             'Physiological Episodes',
    'url': ''

Get single item (story, comment, poll, etc) by ID or username


Example of how to turn the items returned by a query into a plaintext file, one item per line

Check out the source to see available methods or for more examples - better docs soon