Python PRAW - Getting the list of trophies a redditor has

Python PRAW - Getting the list of trophies a redditor has

To get the list of trophies a Redditor has using the praw library in Python, you can utilize the trophies() method of a Redditor object. Here's a step-by-step guide:

  • First, ensure you have praw installed:
pip install praw 
  • Create a Reddit app for using the PRAW API. Follow these steps:

    • Go to https://www.reddit.com/prefs/apps
    • Scroll down to the "Developed Applications" section and click on "Create App" or "Create Another App".
    • Fill out the form:
      • name: A name for your application.
      • App type: Script.
      • description: Can be left blank.
      • permissions: Read.
      • redirect uri: http://localhost:8080 (or any other unused local address).
      • Agree to the terms and click on "Create app".
  • After creating the app, note down the client_id (right under the app name) and client_secret.

  • Use praw to get the list of trophies:

import praw # Initialize the Reddit client reddit = praw.Reddit( client_id='YOUR_CLIENT_ID', client_secret='YOUR_CLIENT_SECRET', user_agent='a_descriptive_user_agent' ) # Replace 'reddit_username' with the desired Reddit user's name redditor = reddit.redditor('reddit_username') # Get the list of trophies trophies = redditor.trophies() # Print out trophy details for trophy in trophies: print(trophy.name) # Name of the trophy print(trophy.icon_70) # URL to the 70x70 icon for the trophy print("---") 

Replace 'YOUR_CLIENT_ID' and 'YOUR_CLIENT_SECRET' with the client_id and client_secret from your Reddit app. The 'a_descriptive_user_agent' can be something like 'trophies_list_v1'.

Running the code will print out the list of trophies for the specified Reddit user.


More Tags

kubernetes-cronjob ibm-cloud row-height android-kenburnsview amazon-s3 daterangepicker video ubuntu-16.04 android-context jpeg

More Programming Guides

Other Guides

More Programming Examples