Skip to content

Commit

Permalink
Enable for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksergeant committed Nov 27, 2011
1 parent 93e8a40 commit 5e58af2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Retrieve a user's comment threads, and print the output as JSON (default):

hackernews.py comments -u 'username' -p 'password'

Retrieve all comments, and print the output as XML (this might take a while):

hackernews.py comments -all -e xml -u 'username' -p 'password'

Help for the `comments` subcommand:

hackernews.py comments -h
21 changes: 19 additions & 2 deletions hackernews.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ def _get_comments(**kwargs):
'date': comment['date'],
})

# If we're getting all comments.
if kwargs['args'].all:

# Find the 'More' link and load it.
last = J('a', J('table table tr td.title:last'))
if last.text() == 'More':
kwargs['r'] = requests.get('https://news.ycombinator.com%s' % last.attr('href'),
cookies=cookies)

# Check to make sure we have a good response.
if not _good_response(**kwargs):
kwargs.pop('r')
return _get_comments(**kwargs)

# Call this function again, this time with the new list.
return _get_comments(**kwargs)

return kwargs['comments']


Expand Down Expand Up @@ -314,8 +331,8 @@ def comments(args):
required=True)
comments_parser.add_argument('-e', '--export', dest='export', help='Export type',
required=False, default='json', choices=EXPORT_TYPES)
#comments_parser.add_argument('--all', dest='all', help='Get all comments',
#action='store_true')
comments_parser.add_argument('--all', dest='all', help='Get all comments',
action='store_true')
comments_parser.add_argument('--no-cookies', dest='no_cookies', help="Don't use cookies",
action='store_true', default=False)
comments_parser.set_defaults(func=comments)
Expand Down

0 comments on commit 5e58af2

Please sign in to comment.