Python PRAW - Getting the time when a redditor created their account

Python PRAW - Getting the time when a redditor created their account

To get the time when a redditor created their account using the praw (Python Reddit API Wrapper) module, you'd want to access the created_utc attribute of a Redditor object.

Here's a simple example to get the account creation date of a specified user:

  • First, you'll need to set up praw. If you haven't installed it yet, do so using pip:
pip install praw 
  • Next, you'll need to set up an application on the Reddit website to get the client ID, secret, and a user agent string. Visit the following URL and create a new application: https://www.reddit.com/prefs/apps

  • With your credentials ready, here's a basic script to fetch the account creation date:

import praw import datetime # Your client ID, secret, and user agent from the Reddit application page client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET' user_agent = 'YOUR_USER_AGENT_STRING' # Initialize the Reddit instance reddit = praw.Reddit(client_id=client_id, client_secret=client_secret, user_agent=user_agent) # Replace 'example_username' with the Reddit username you want to check redditor = reddit.redditor('example_username') # Convert the creation timestamp to a readable datetime object creation_date = datetime.datetime.utcfromtimestamp(redditor.created_utc) print(f"{redditor.name}'s account was created on {creation_date.strftime('%Y-%m-%d %H:%M:%S')} UTC") 

Replace 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', and 'YOUR_USER_AGENT_STRING' with your actual values. You should also replace 'example_username' with the Reddit username you're interested in.

Run the script, and it'll print out the account creation date for the specified user.


More Tags

readonly git-bash date-arithmetic eloquent iconv angularjs-validation kiosk-mode ef-core-2.1 python-requests asyncfileupload

More Programming Guides

Other Guides

More Programming Examples