def setUp(self): httpretty.HTTPretty.enable() httpretty.register_uri(httpretty.GET, 'https://news.ycombinator.com/', body=get_content('index.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'item?id=7324236'), body=get_content('7324236.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=0MonpGsCkcGbA7rcbd2BAP'), body=get_content('7324236-2.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=jyhCSQtM6ymFazFplS4Gpf'), body=get_content('7324236-3.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=s3NA4qB6zMT3KHVk1x2MTG'), body=get_content('7324236-4.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=pFxm5XBkeLtmphVejNZWlo'), body=get_content('7324236-5.html')) story = Story.fromid(7324236) self.comments = story.get_comments()
def setUp(self): self.PY2 = sys.version_info[0] == 2 if not self.PY2: self.text_type = [str] else: self.text_type = [unicode, str] self.story = Story.fromid(6115341) # https://news.ycombinator.com/item?id=6115341
def setUp(self): httpretty.HTTPretty.enable() httpretty.register_uri(httpretty.GET, 'https://news.ycombinator.com/', body=get_content('index.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'item?id=7324236'), body=get_content('7324236.html')) httpretty.register_uri( httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=0MonpGsCkcGbA7rcbd2BAP'), body=get_content('7324236-2.html')) httpretty.register_uri( httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=jyhCSQtM6ymFazFplS4Gpf'), body=get_content('7324236-3.html')) httpretty.register_uri( httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=s3NA4qB6zMT3KHVk1x2MTG'), body=get_content('7324236-4.html')) httpretty.register_uri( httpretty.GET, '%s/%s' % (constants.BASE_URL, 'x?fnid=pFxm5XBkeLtmphVejNZWlo'), body=get_content('7324236-5.html')) story = Story.fromid(7324236) self.comments = story.get_comments()
def setUp(self): self.PY2 = sys.version_info[0] == 2 if not self.PY2: self.text_type = [str] else: self.text_type = [unicode, str] self.story = Story.fromid( 6115341) # https://news.ycombinator.com/item?id=6115341
def comments(story_id): """ show comments for the story """ comments = Story.fromid(story_id).get_comments() if not comments: echo(style('no coments for story found!', fg='red')) for comment in comments: echo(style(comment.time_ago.center(15), fg='magenta'), nl=False) echo('by ' + style(str(comment.user), fg='cyan')) echo(comment.body)
def setUp(self): httpretty.HTTPretty.enable() httpretty.register_uri(httpretty.GET, 'https://news.ycombinator.com/', body=get_content('index.html')) httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'item?id=6115341'), body=get_content('6115341.html')) # check py version self.PY2 = sys.version_info[0] == 2 self.hn = HN() self.story = Story.fromid(6115341)
def setUp(self): httpretty.HTTPretty.enable() httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL, 'item?id=6115341'), body=get_content('6115341.html')) self.PY2 = sys.version_info[0] == 2 if not self.PY2: self.text_type = [str] else: self.text_type = [unicode, str] # https://news.ycombinator.com/item?id=6115341 self.story = Story.fromid(6115341)
print(comments[0] if len(comments) > 0 else None) print('*' * 10) # print top 5 comments with nesting for top 5 stories for story in hn.get_stories(story_type='best', limit=5): print(story.title) comments = story.get_comments() if len(comments) > 0: for comment in comments[:5]: print('\t' * (comment.level + 1) + comment.body[:min(30, len(comment.body))]) print('*' * 10) # get the comments from any custom story story = Story.fromid(6374031) comments = story.get_comments() ########NEW FILE######## __FILENAME__ = test_leaders import unittest from hn import HN, Story from hn import utils, constants from test_utils import get_content, PRESETS_DIR import httpretty class TestGetLeaders(unittest.TestCase):
def test_get_nested_comments_old_story(self): self.story = Story.fromid(7410260) self.comments = self.story.get_comments() comment = self.comments[0].body self.assertEqual(len(comment), 2131)
def test_get_nested_comments(self): self.story = Story.fromid(7404389) self.comments = self.story.get_comments() comment = self.comments[0].body self.assertTrue(len(comment) >= 5508)
def comment(story_id): """ comment story on HackerNews """ story = Story.fromid(story_id) click.launch(story.comments_link)
def go(story_id): """ go to the story on HackerNews """ story = Story.fromid(story_id) click.launch(story.link)
def setUp(self): # check py version self.PY2 = sys.version_info[0] == 2 self.hn = HN() self.story = Story.fromid(6374031)
def setUp(self): self.story = Story.fromid(7324236)
# print 10 latest stories for story in hn.get_stories(story_type='newest', limit=10): print((story.title.encode('utf-8'))) print(('*' * 50)) print('') # for each story on front page, print top comment for story in hn.get_stories(): print((story.title.encode('utf-8'))) comments = story.get_comments() print((comments[0] if len(comments) > 0 else None)) print(('*' * 10)) # print top 5 comments with nesting for top 5 stories for story in hn.get_stories(story_type='best', limit=5): print((story.title.encode('utf-8'))) comments = story.get_comments() if len(comments) > 0: for comment in comments[:5]: print(('\t' * (comment.level + 1) + comment.body[:min(30, len(comment.body))])) print(('*' * 10)) # get the comments from any custom story story = Story.fromid(6374031) comments = story.get_comments()