Screen Link:
4. Getting Post Comments
Retrieve the comments on it using the /r/{subreddit}/comments/{article} endpoint
Where it says article I have replaced it with the name of the person who wrote the article and I have obtained a response:
My Code:
python_top_articles=res.json()['data']['children']
most_upvoted = ""
most_upvotes = 0
for article in python_top_articles:
ar = article["data"]
if ar["ups"] >= most_upvotes:
most_upvoted = ar["id"]
most_upvotes = ar["ups"]
print("most_upvoted: ", most_upvoted, " most_upvotes: ", most_upvotes)
most_upvoted: tjodin most_upvotes: 517
article = requests.get(OAuth + '/r/python/comments/tjodin', headers=headers, params=params)
article.json()
<Output:>
[{'kind': 'Listing',
'data': {'after': None,
'dist': 1,
'modhash': None,
'geo_filter': '',
'children': [{'kind': 't3',
'data': {'approved_at_utc': None,
'subreddit': 'Python',
'selftext': "For those that don't know, Pandas has very useful to_clipboard and read_clipboard methods that make it easy to drop a DataFrame into an Excel sheet or to move it across python sessions without having to read and write CSV files. This is really useful for me and I hope it will help you too!",
'user_reports': [],
'saved': False,
'mod_reason_title': None,
'gilded': 0,
'clicked': False,
'title': 'LPT: Pandas DataFrames have a "to_clipboard" method',
'link_flair_richtext': [{'e': 'text', 't': 'Discussion'}],
'subreddit_name_prefixed': 'r/Python',
'hidden': False,
'pwls': 6,
.
.
.
# getting the most voted comment.
comment = article.json()[0]['data']['children'][0]['data']['selftext'] # number one voted post (at least now!)
comment
"For those that don't know, Pandas has very useful to_clipboard and read_clipboard methods that make it easy to drop a DataFrame into an Excel sheet or to move it across python sessions without having to read and write CSV files. This is really useful for me and I hope it will help you too!"
It seems like it’s the right thing to do, right?
Thank you very much.
A&E.