Package: haxor
haxorUnofficial Python wrapper for official Hacker News API.InstallationpipinstallhaxorUsageImport and initialization:fromhackernewsimportHackerNewshn=HackerNews()ItemsStories, comments, jobs, Ask HNs and even polls are just items with unique item id.To query item information by id:item=hn.get_item(8863)# >>> item.title# 'My YC app: Dropbox - Throw away your USB drive'# >>> item.item_type# 'story'# >>> item.kids# [ 8952, 9224, 8917, ...]Since most results are returned as integer IDs (like item.kids above), these results require further iteration.  Instead of doing this yourself, use theexpandflag to get object-oriented, detailed item info by id:item=hn.get_item(8863,expand=True)# >>> item.kids# [<hackernews.Item: 9224 - None>, <hackernews.Item: 8952 - None>, ...]# >>> item.by# <hackernews.User: dhouston>To query a list of Item IDs:items=hn.get_items_by_ids([8863,37236,2345])# >>> items# [<hackernews.Item: 8863 - My YC app: Dropbox - Throw away your USB drive>, <hackernews.Item:# 37236 - None>, <hackernews.Item: 2345 - The Best Buy Scam.>]Use theitem_typefilter to specifically select 'story', 'comment', 'job', or 'poll' items:items=hn.get_items_by_ids([8863,37236,2345],item_type='story')# >>> items# [<hackernews.Item: 8863 - My YC app: Dropbox - Throw away your USB drive>, <hackernews.Item: # 2345 - The Best Buy Scam.>]StoriesThe HN API allows for real-time querying for New, Top, Best, Ask HN, Show HN, and Jobs stories.As an example, to get Item objects of current top stories:top_stories=hn.top_stories()# >>> top_stories# [<hackernews.Item: 16924667 - Ethereum Sharding FAQ>, ...]Useful Item QueriesTo get current largest Item id (most recent story, comment, job, or poll):max_item=hn.get_max_item()# >>> max_item# 16925673Once again, use theexpandflag to get an object-oriented, detailed Item representation:max_item=hn.get_max_item(expand=True)# >>> max_item# <hackernews.Item: 16925673 - None>To get the x most recent Items:last_ten=hn.get_last(10)# >>> last_ten# [<hackernews.Item: 16925688 - Show HN: Eventbot – Group calendar for Slack teams>, ...]UsersHN users are also queryable.To query users by user_id (i.e. username on Hacker News):user=hn.get_user('pg')# >>> user.user_id# 'pg'# >>> user.karma# 155040Use theexpandflag to get an object-oriented, detailed Item representation for User attributes:user=hn.get_user('dhouston',expand=True)# >>> user.stories# [<hackernews.Item: 1481914 - Dropbox is hiring a Web Engineer>, ...]# >>> user.comments# [<hackernews.Item: 16660140 - None>, <hackernews.Item: 15692914 - None>, ...]# >>> user.jobs# [<hackernews.Item: 3955262 - Dropbox seeking iOS and Android engineers>, ...]To query a list of users:users=hn.get_users_by_ids(['pg','dhouston'])# >>> users# [<hackernews.User: pg>, <hackernews.User: dhouston>]ExamplesGet top 10 stories:hn.top_stories(limit=10)# [<hackernews.Item: 16924667 - Ethereum Sharding FAQ>, <hackernews.Item: 16925499 - PipelineDB # v0.9.9 – One More Release Until PipelineDB Is a PostgreSQL Extension>, ...]Find all the 'jobs' post from Top Stories:stories=hn.top_stories()forstoryinstories:ifstory.item_type=='job':print(story)# <hackernews.Item: 16925047 - Taplytics (YC W14) is solving hard engineering problems in# Toronto and hiring># ...# ...Find Python jobs from monthly who is hiring thread:# Who is hiring - April 2018# https://news.ycombinator.com/item?id=16735011who_is_hiring=hn.get_item(16735011,expand=True)forcommentinwho_is_hiring.kids:if'python'incomment.text.lower():print(comment)# <hackernews.Item: 16735358 - None># <hackernews.Item: 16737152 - None># ...# ...API ReferenceClass:HackerNewsParameters:NameTypeRequiredDescriptionDefaultversionstringNospecifies Hacker News API versionv0get_itemDescription: ReturnsItemobjectParameters:NameTypeRequiredDescriptionDefaultitem_idstring/intYesunique item id of Hacker News story, comment etcNoneexpandboolNoflag to indicate whether to transform all IDs into objectsFalseget_items_by_idsDescription: Returns list ofItemobjectsParameters:NameTypeRequiredDescriptionDefaultitem_idslist of string/intYesunique item ids of Hacker News stories, comments etcNoneitem_typestringNoitem type to filter results withNoneget_userDescription: ReturnsUserobjectParameters:NameTypeRequiredDescriptionDefaultuser_idstringYesunique user id of a Hacker News userNoneexpandboolNoflag to indicate whether to transform all IDs into objectsFalseget_users_by_idsDescription: Returns list ofUserobjectsParameters:NameTypeRequiredDescriptionDefaultuser_idslist of string/intYesunique user ids of Hacker News usersNonetop_storiesDescription: Returns list ofItemobjects of current top storiesParameters:NameTypeRequiredDescriptionDefaultrawboolNoindicate whether to represent all objects in raw jsonFalselimitintNospecifies the number of stories to be returnedNonenew_storiesDescription: Returns list ofItemobjects of current new storiesParameters:NameTypeRequiredDescriptionDefaultrawboolNoindicate whether to represent all objects in raw jsonFalselimitintNospecifies the number of stories to be returnedNoneask_storiesDescription: Returns list ofItemobjects of latest Ask HN storiesParameters:NameTypeRequiredDescriptionDefaultrawboolNoindicate whether to represent all objects in raw jsonFalselimitintNospecifies the number of stories to be returnedNoneshow_storiesDescription: Returns list ofItemobjects of latest Show HN storiesParameters:NameTypeRequiredDescriptionDefaultrawboolNoindicate whether to represent all objects in raw jsonFalselimitintNospecifies the number of stories to be returnedNonejob_storiesDescription: Returns list ofItemobjects of latest Job storiesParameters:NameTypeRequiredDescriptionDefaultrawboolNoindicate whether to represent all objects in raw jsonFalselimitintNospecifies the number of stories to be returnedNoneupdatesDescription: Returns list ofItemandUserobjects that have been changed/updated recently.Parameters:N/Aget_max_itemDescription: Returns current largest item id or current largestItemobjectParameters:NameTypeRequiredDescriptionDefaultexpandboolNoflag to indicate whether to transform ID into objectFalseget_allDescription: Returns allItemobjects from HNParameters:N/Aget_lastDescription: Returns list ofnummost recentItemobjectsParameters:NameTypeRequiredDescriptionDefaultnumintNonumbr of most recent records to pull from HN10Class:ItemFromOfficial HackerNews
Item:PropertyDescriptionitem_idThe item’s unique id.deletedtrueif the item is deleted.item_typeThe type of item. One of “job”, “story”, “comment”, “poll”, or “pollopt”.byThe username of the item’s author.submission_timeCreation date of the item, in Pythondatetime.textThe comment, Ask HN, or poll text. HTML.deadtrueif the item is dead.parentThe item’s parent. For comments, either another comment or the relevant story. For pollopts, the relevant poll.pollThe ids of poll's.kidsThe ids of the item’s comments, in ranked display order.urlThe URL of the story.scoreThe story’s score, or the votes for a pollopt.titleThe title of the story or poll.partsA list of related pollopts, in display order.descendantsIn the case of stories or polls, the total comment count.raworiginal JSON response.Class:UserFromOfficial HackerNews
User:PropertyDescriptionuser_idThe user’s unique username. Case-sensitive.delayDelay in minutes between a comment’s creation and its visibility to other users.createdCreation date of the user, in Pythondatetime.karmaThe user’s karma.aboutThe user’s optional self-description. HTML.submittedList of the user’s stories, polls and comments.raworiginal JSON response.Additional properties whenexpandis usedPropertyDescriptionstoriesThe user’s submitted stories.commentsThe user's submitted comments.jobsThe user's submitted jobs.pollsThe user's submitted polls.polloptsThe user's submitted poll options.DevelopmentFor local development dopipinstallation ofrequirements-dev.txt:pip install -r requirements-dev.txtTestingRun the test suite by running:echo "0.0.0-dev" > version.txt
python setup.py develop
pytest testsLICENSEThe mighty MIT license. Please checkLICENSEfor more details.