6.2.2. Demo & Practice: Author Info#

Though Reddit collects the device/program sources of submissions (like we saw from former President Trump), it unfortunately doesn’t let us see them.

Instead we will look at other information about the author of posts on Reddit that can perhaps tell us something about their authenticity.

Log into Reddit (PRAW)#

These are our normal steps get PRAW loaded and logged into Reddit

import praw

(optional) make a fake praw connection with the fake_praw library

For testing purposes, we’ve added this line of code, which loads a fake version of praw, so it wont actually connect to reddit. If you want to try to actually connect to reddit, don’t run this line of code.

%run ../../fake_apis/fake_praw.ipynb
Fake praw is replacing the praw library. Fake praw doesn't need real passwords, and prevents you from accessing real reddit
# Load all your developer access passwords into Python
# TODO: Put your reddit username, password, and special developer access passwords below:
username="fake_reddit_username"
password="sa@#4*fdf_fake_password_$%DSG#%DG"
client_id="45adf$TW_fake_client_id_JESdsg1O"
client_secret="56sd_fake_client_secret_%Yh%"
# Give the praw code your reddit account info so
# it can perform reddit actions
reddit = praw.Reddit(
    username=username, password=password,
    client_id=client_id, client_secret=client_secret,
    user_agent="a custom python script"
)
Fake praw is pretending to collect account info to use on reddit

Load a set of Reddit posts and look up author information#

The code below searches for recent submissions from a subreddit, and then does a loop though all the tweets, printing out the information about the authors of the submissions, such as:

  • Link Karma (a measure of how much people like the links that person submits)

  • Comment Karma (a measure of how much people like the comments that person makes)

Try searching through other subreddits and see what you notice about the authors of posts in different subreddits.

To do this:

  • put in your special Reddit bot passwords

  • skip the fake_tweepy step above

  • take the first line of the code below and replace cuteanimals with a different subreddit name, like movies

# Look up the subreddit "cuteanimals", then find the "hot" list, getting up to 10 submission
submissions = reddit.subreddit("cuteanimals").hot(limit=10)

# Turn the submission results into a Python List
submissions_list = list(submissions)

for submission in submissions_list:
    print("Info for submission: " + str(submission.title))
    print("  author: " + str(submission.author))
    print("  author's Link Karma: " + str(submission.author.link_karma))
    print("  author's Comment Karma: " + str(submission.author.comment_karma))
    print("  author has a verified email address? " + str(submission.author.has_verified_email))
    print("  author is a moderator of a subreddit? " + str(submission.author.is_mod))
    print("  author has active Reddit Premium status? " + str(submission.author.is_gold))
    print()
Fake praw is pretending to select the subreddit: cuteanimals
Info for submission: Look at my cute dog!
  author: fake_user
  author's Link Karma: 10
  author's Comment Karma: 50
  author has a verified email address? True
  author is a moderator of a subreddit? False
  author has active Reddit Premium status? False

Info for submission: A baby lizard!
  author: pretend_user
  author's Link Karma: 25
  author's Comment Karma: 15
  author has a verified email address? True
  author is a moderator of a subreddit? True
  author has active Reddit Premium status? False

Info for submission: The cutest bird ever!
  author: imaginary_user
  author's Link Karma: 3
  author's Comment Karma: 7
  author has a verified email address? True
  author is a moderator of a subreddit? True
  author has active Reddit Premium status? True