HackerNewsAPI icon indicating copy to clipboard operation
HackerNewsAPI copied to clipboard

Comment.body_html is incomplete

Open nucleartide opened this issue 12 years ago • 9 comments

from hn import Story
story = Story.fromid(7324236)
comments = story.get_comments()
print comments[0].body
print comments[0].body_html

Seems like .body_html only returns a portion of the comment body's HTML.

nucleartide avatar Mar 14 '14 01:03 nucleartide

I can see why this is happening....each sub-comment is treated as a separate comment. so if u print comments[1].body_html u will get the first reply to comments[0].body_html. i will try to fix it unless Karan can fix it before me :)

ueg1990 avatar Mar 14 '14 16:03 ueg1990

You for it @ueg1990!

karan avatar Mar 15 '14 15:03 karan

hey karan, i thin i fixed the problem. what i did was for each comment that had nested comments, i aded it to the current comment but still treated each comment as separate comments too. that is if comments[0] has comments[1] and comments[2] as nested comments, i concatenate the body and body_html of both comments[1] and comments[2] to comments[0], but comments[1] and comments[2] are still in the comments array. I know the explanation is confusing but i will add a pull request and u can have a look and let me know what you think. :)

ueg1990 avatar Mar 15 '14 17:03 ueg1990

The code makes sense and tests are passing. Good job! :)

karan avatar Mar 16 '14 15:03 karan

just to confirm, do u want this functionality to only be for comments at level 0?? as in retrieve all the comments only for at level 0?

ueg1990 avatar Mar 16 '14 15:03 ueg1990

@ueg1990 I think it's better to have it for all to keep the API consistent.

karan avatar Mar 19 '14 19:03 karan

as in u want all comments under level 1 to be concatenated to its body and so on for comments at other levels??

ueg1990 avatar Mar 19 '14 19:03 ueg1990

I'm not sure what you mean, but comments should be in JSON format, with a list of individual comments.

The next level of this, is to make nested dicts. So comments[0] means the first comment, comments[0][0] means the first reply of first comment etc. This is where the level field will be useful.

Also, make sure to update the README as the code evolves to keep it in sync with the features.

karan avatar Mar 19 '14 20:03 karan

Ok, looks a bit tricky. will let you know if i need some help.

On Wed, Mar 19, 2014 at 4:00 PM, Karan Goel [email protected]:

I'm not sure what you mean, but comments should be in JSON format, with a list of individual comments.

The next level of this, is to make nested dicts. So comments[0] means the first comment, comments[0][0] means the first reply of first comment etc. This is where the level field will be useful.

Also, make sure to update the README as the code evolves to keep it in sync with the features.

Reply to this email directly or view it on GitHubhttps://github.com/karan/HackerNewsAPI/issues/30#issuecomment-38099632 .

USman

ueg1990 avatar Mar 19 '14 20:03 ueg1990