-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-reddit-chatgpt-collect-posts.Rmd
executable file
·133 lines (111 loc) · 3.56 KB
/
1-reddit-chatgpt-collect-posts.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
title: "Generative AI Generating Buzz: Volume, Engagement, and Content of Initial Reactions to ChatGPT in Discussions Across Education-Related Subreddits"
author: "Bret Staudt Willet"
date: "2023-04-04"
output: html_document
---
## Set Up
```{r setup}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(reticulate)
library(RedditExtractoR)
library(anytime)
library(lubridate)
```
```{r python-setup, eval=FALSE}
#version <- "3.11.1"
#install_python(version)
#install_miniconda()
#use_python_version(version)
#use_python("/Users/kstaudtwillet/.pyenv/versions/3.11.1/bin/python3.11")
#py_config()
```
```{r condaenv-setup}
##### create a new environment #####
#conda_create("~/r-reticulate")
##### indicate that we want to use a specific condaenv #####
use_condaenv("~/r-reticulate")
##### install Python packages as needed #####
#conda_install("r-reticulate", "praw")
#conda_install("r-reticulate", "pmaw") # install with pip3 install pmaw
#conda_install("r-reticulate", "datetime")
#conda_install("r-reticulate", "scipy")
#conda_install("r-reticulate", "pandas")
#conda_install("r-reticulate", "seaborn")
#conda_install("r-reticulate", "matplotlib.pyplot"). # does not install: private package
### import PRAW (will use "r-reticulate" as per call to use_condaenv)
#scipy <- import("scipy")
#praw <- import("praw")
```
```{python setup}
import pandas as pd
pd.__file__
import datetime as dt
dt.__file__
```
```{r, include=FALSE}
my_client_id <- Sys.getenv('praw_client_id')
my_client_secret <- Sys.getenv('praw_client_token')
my_user_agent <- Sys.getenv('praw_user_agent')
```
```{python, include=FALSE}
import praw
reddit = praw.Reddit(
client_id = r.my_client_id,
client_secret = r.my_client_secret,
user_agent = r.my_user_agent
)
```
```{python initialize_PushShift}
from pmaw import PushshiftAPI
api_praw = PushshiftAPI(praw = reddit)
```
## Get Posts
```{python}
start_epoch = int(dt.datetime(2023, 2, 1).timestamp())
end_epoch = int(dt.datetime(2023, 4, 1).timestamp())
```
```{r}
ren <- c(
"education", "Teachers", "teachingresources", "edtech",
"AdultEducation", "ArtEd", "CSEducation", "ECEProfessionals",
"ELATeachers", "highereducation", "historyteachers", "itinerantteachers",
"matheducation", "MusicEd", "ScienceTeachers", "slp",
"specialed", "TeachersPromote", "TeachersInTransition", "teaching",
"Professors", "academia", "instructionaldesign", "TeacherTales",
"OnlineEducation"
)
```
```{python}
#r.ren[0]
posts_praw = api_praw.search_submissions(q = "chatgpt",
subreddit = "education",
after = start_epoch,
before = end_epoch,
limit = 100
)
post_list = [post for post in posts_praw]
posts_df = pd.DataFrame(post_list)
```
```{r}
posts_df_r <-
py$posts_df %>%
select(created_utc, subreddit, id, author, title, selftext,
num_comments, score, ups, downs, upvote_ratio, permalink, url) %>%
rename(post_id = id,
post_date_time = created_utc,
post_text = selftext) %>%
mutate(subreddit = stringr::str_remove(permalink, "/"),
subreddit = stringr::str_remove_all(subreddit, "/comments.*"),
post_date_time = anytime::anytime(post_date_time, asUTC=TRUE),
post_date_time = lubridate::ymd_hms(lubridate::as_datetime(post_date_time)),
post_date_time = lubridate::with_tz(post_date_time, tzone='US/Eastern'),
date = date(post_date_time),
year = year(post_date_time)) %>%
distinct(post_id, .keep_all = TRUE)
posts_df_r$subreddit[1]; min(posts_df_r$date); max(posts_df_r$date); nrow(posts_df_r)
```
```{r}
write_csv(posts_df_r, "./data-gpt/r-education-posts-gpt.csv")
```