-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-reddit-chatgpt-consolidate-posts.Rmd
executable file
·210 lines (178 loc) · 4.76 KB
/
2-reddit-chatgpt-consolidate-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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
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 condaenv-setup}
use_condaenv("~/r-reticulate")
```
```{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)
```
## Consolidate posts from different subreddits
```{r, eval=FALSE, message=FALSE}
posts_raw <-
list.files(path = "./data-gpt/",
pattern = "*.csv",
full.names = TRUE) %>%
map_df(~read_csv(.)) %>%
mutate(post_date_time = with_tz(post_date_time, tzone = "US/Eastern")) %>%
distinct(post_id, .keep_all = TRUE) %>%
filter()
```
```{r, eval=FALSE, message=FALSE}
write_csv(posts_raw, "./data-gpt/!all-posts-raw.csv")
```
```{r, eval=FALSE, message=FALSE}
all_posts <- read_csv("./data-gpt/!all-posts-raw.csv")
```
```{r}
first_post <-
all_posts %>%
group_by(subreddit) %>%
summarize(earliest_gpt_date = min(date)) %>%
arrange(earliest_gpt_date)
first_post
```
```{r}
chatgpt_count <-
all_posts %>%
group_by(subreddit) %>%
count() %>%
rename(chatgpt_post_n = n) %>%
arrange(desc(chatgpt_post_n))
chatgpt_count
```
```{r}
ren <- c(
"r/education", "r/Teachers", "r/teachingresources", "r/edtech",
"r/AdultEducation", "r/ArtEd", "r/CSEducation", "r/ECEProfessionals",
"r/ELATeachers", "r/highereducation", "r/historyteachers", "r/itinerantteachers",
"r/matheducation", "r/MusicEd", "r/ScienceTeachers", "r/slp",
"r/specialed", "r/TeachersPromote", "r/TeachersInTransition", "r/teaching",
"r/Professors", "r/academia", "r/instructionaldesign", "r/TeacherTales",
"r/OnlineEducation"
)
```
```{python}
feb_start = int(dt.datetime(2023, 2, 1).timestamp())
feb_end = int(dt.datetime(2023, 2, 28).timestamp())
mar_start = int(dt.datetime(2023, 3, 1).timestamp())
mar_end = int(dt.datetime(2023, 3, 31).timestamp())
```
```{python}
posts = api_praw.search_submissions(
subreddit = "TeacherTales",
after = feb_start,
before = mar_end,
limit = 1000
)
post_list = [post for post in posts]
posts_df = pd.DataFrame(post_list)
posts_df.shape
```
```{r education}
sum(472, 698)
```
```{r slp}
sum(647, 821)
```
```{r teaching}
sum(449, 490)
```
```{r Professors}
sum(381, 409) + sum(420, 515)
```
```{r Teachers}
sum(870, 814, 837, 767) + sum(860, 796, 767, 840, 361)
```
```{r}
ren <- c(
"r/education", "r/Teachers", "r/teachingresources", "r/edtech",
"r/AdultEducation", "r/ArtEd", "r/CSEducation", "r/ECEProfessionals",
"r/ELATeachers", "r/highereducation", "r/historyteachers", "r/itinerantteachers",
"r/matheducation", "r/MusicEd", "r/ScienceTeachers", "r/slp",
"r/specialed", "r/TeachersPromote", "r/TeachersInTransition", "r/teaching",
"r/Professors", "r/academia", "r/instructionaldesign", "r/TeacherTales",
"r/OnlineEducation"
)
total_post_n <-
c(1170, 6912, 322, 142,
13, 103, 40, 724,
156, 394, 146, 0,
142, 149, 279, 1468,
330, 27, 648, 939,
1725, 747, 356, 71,
251
)
total_posts <-
tibble(ren, total_post_n) %>%
rename(subreddit = ren)
total_posts
```
```{r}
chatgpt_table <-
tibble(first_post) %>%
left_join(chatgpt_count, by="subreddit") %>%
left_join(total_posts, by="subreddit") %>%
replace(is.na(.), 0) %>%
mutate(p_posts = 100*chatgpt_post_n/total_post_n) %>%
arrange(subreddit)
chatgpt_table
```
```{r}
posts <-
all_posts %>%
left_join(chatgpt_table, by="subreddit") %>%
mutate(status = ifelse(post_text == "[deleted]",
"deleted",
ifelse(post_text == "[removed]",
"removed",
"remaining")),
status = ifelse(is.na(status),
"remaining",
status),
post_url = paste0("https://www.reddit.com", permalink)
)
posts %>% count(status)
```
```{r}
filtered_posts <-
posts %>%
filter(status == "remaining")
nrow(filtered_posts); paste("Expected number of comments:", sum(filtered_posts$num_comments))
```
```{r, eval=FALSE}
write_csv(posts, "./data-gpt/!all-posts.csv")
write_csv(filtered_posts, "./data-gpt/!filtered-posts.csv")
```