{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "05cba5c5-235c-439a-ba7d-96944877f000", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02) \n", "[Clang 11.1.0 ]\n" ] } ], "source": [ "# Use svg graphics, display inline\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'svg'\n", "\n", "import sys\n", "\n", "# Basic scientific computing imports\n", "import numpy as np\n", "import pandas as pd\n", "\n", "# display config\n", "pd.set_option('display.float_format', lambda x: '%.3f' % x)\n", "np.set_printoptions(suppress=True)\n", "\n", "# ad hoc imports\n", "import requests\n", "import json\n", "import os\n", "import praw\n", "\n", "print(sys.version)" ] }, { "cell_type": "markdown", "id": "87c2ffab-4488-4d46-9fda-f2ef31399336", "metadata": {}, "source": [ "# Subreddit Discovery with PRAW\n", "\n", "Reddit is the Wild West of the internet. Unlike many modern social platforms, it's structured into communities that each have their own purpose and standards. Instead of adding people to your personal network, you can explore and join these communitites to get a taste of what they're about.\n", "\n", "**Thought Experiment**: How would you go about finding new communities of people irl, without Reddit. Or the internet. Like if you actually had to get out of the house and meet people. Imagine you're dropped into a new city in 1985 and you don't know a single soul.\n", "\n", "The first thing you might do is find the community you're most familiar with. Somewhere where you're already familiar with the customs and know how to maneuver. For me, that community is probably `/r/bjj`, but we can use `/r/datascience` (I know you nerds love data science). Let's use PRAW to get the titles of the 10 hottest posts in that community." ] }, { "cell_type": "code", "execution_count": 2, "id": "b8dd40e7-271d-4dd2-bb04-eb51f7851eea", "metadata": {}, "outputs": [], "source": [ "session_params = {\n", " 'user_agent': '',\n", " 'client_id': '', \n", " 'client_secret': '',\n", "}\n", "\n", "reddit = praw.Reddit(**session_params)" ] }, { "cell_type": "code", "execution_count": 3, "id": "bc73d35e-abbb-417e-ae05-2447357f611a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | date | \n", "title | \n", "author | \n", "day_of_week | \n", "hour | \n", "score | \n", "upvote_ratio | \n", "comment_count | \n", "post_id | \n", "url | \n", "
---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "2021-11-07 | \n", "Weekly Entering & Transitioning Thread | 07 No... | \n", "datascience-bot | \n", "Sunday | \n", "12 | \n", "2 | \n", "0.750 | \n", "7 | \n", "qon4ml | \n", "https://www.reddit.com/r/datascience/comments/... | \n", "
1 | \n", "2021-11-07 | \n", "What is something you took the time to learn t... | \n", "THE_REAL_ODB | \n", "Sunday | \n", "15 | \n", "124 | \n", "0.980 | \n", "46 | \n", "qore0i | \n", "https://www.reddit.com/r/datascience/comments/... | \n", "
2 | \n", "2021-11-07 | \n", "I start working among a team of Data Scientist... | \n", "Abdullah_super | \n", "Sunday | \n", "4 | \n", "72 | \n", "0.920 | \n", "21 | \n", "qohgdl | \n", "https://www.reddit.com/r/datascience/comments/... | \n", "
3 | \n", "2021-11-07 | \n", "What is your go-to resources for learning new ... | \n", "aero_gsr | \n", "Sunday | \n", "20 | \n", "3 | \n", "0.720 | \n", "4 | \n", "qox4rs | \n", "https://www.reddit.com/r/datascience/comments/... | \n", "
4 | \n", "2021-11-07 | \n", "Use of data science in new small start-ups | \n", "powermed2404 | \n", "Sunday | \n", "16 | \n", "6 | \n", "0.690 | \n", "10 | \n", "qos332 | \n", "https://www.reddit.com/r/datascience/comments/... | \n", "