项目作者: nicolashahn

项目描述 :
Search Hacker News with Python
高级语言: Python
项目地址: git://github.com/nicolashahn/py-search-hn.git
创建时间: 2017-10-02T12:38:31Z
项目社区:https://github.com/nicolashahn/py-search-hn

开源协议:MIT License

下载


py-search-hn

Search Hacker News with Python

  1. from search_hn import SearchHN
  2. hn = SearchHN()

String together methods to build queries

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

Or just use the non-composable methods for quick results

  1. >>> print(hn.get_latest_stories()[0])
  2. { '_tags': ['story', 'author_smacktoward', 'story_15383441'],
  3. 'author': 'smacktoward',
  4. 'title': 'Carrier Deployment Raises Questions About Navy’s Rash of '
  5. 'Physiological Episodes',
  6. 'url': 'https://news.usni.org/2017/10/02/recent-carrier-deployment-raises-questions-navys-rash-physiological-episodes'
  7. ...

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

  1. hn.get_item(1234)
  2. hn.get_user('nicolashahn')

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 example.py for more examples - better docs soon