File size: 10,603 Bytes
749d1d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "730ba509",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.core.interactiveshell import InteractiveShell\n",
    "InteractiveShell.ast_node_interactivity = \"all\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9acd4b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "import sys\n",
    "proj_dir = Path.cwd().parent\n",
    "\n",
    "sys.path.append(str(proj_dir))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62452860",
   "metadata": {},
   "outputs": [],
   "source": [
    "from utilities.pushshift_data import scrape_submissions_by_day, submissions_to_dataframe, get_post_count_for_day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a956a623",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "17df3f2812084d3591e914ffcfd948b0",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "0it [00:00, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-04-12 16:23:59,392 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-03-01 20:00:00\n",
      "2023-04-12 16:24:03,524 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-03-01 14:37:16\n",
      "2023-04-12 16:24:08,443 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-03-01 05:02:52\n",
      "2023-04-12 16:24:13,409 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-03-01 00:43:35\n",
      "2023-04-12 16:24:17,548 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-02-28 20:28:35\n",
      "2023-04-12 16:24:21,490 - INFO - Fetching data between timestamps 2013-02-28 20:00:00 and 2013-02-28 20:00:48\n",
      "2023-04-12 16:24:23,658 - INFO - Finished scraping 4106 submissions in 28.86 seconds\n"
     ]
    }
   ],
   "source": [
    "subreddit_to_scrape = \"askreddit\"\n",
    "day_to_scrape = \"2013-03-01\"\n",
    "submissions = scrape_submissions_by_day(subreddit_to_scrape, day_to_scrape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b1cc845b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>permalink</th>\n",
       "      <th>selftext</th>\n",
       "      <th>url</th>\n",
       "      <th>created_utc</th>\n",
       "      <th>author</th>\n",
       "      <th>num_comments</th>\n",
       "      <th>score</th>\n",
       "      <th>title</th>\n",
       "      <th>id</th>\n",
       "      <th>downs</th>\n",
       "      <th>ups</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>/r/AskReddit/comments/19hbm0/in_the_way_that_p...</td>\n",
       "      <td>Basically, do other parts of the world have th...</td>\n",
       "      <td>http://www.reddit.com/r/AskReddit/comments/19h...</td>\n",
       "      <td>2013-03-01 19:58:55</td>\n",
       "      <td>sjr63</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>In the way that popular English and American m...</td>\n",
       "      <td>19hbm0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>/r/AskReddit/comments/19hblp/could_i_buy_an_an...</td>\n",
       "      <td></td>\n",
       "      <td>http://www.reddit.com/r/AskReddit/comments/19h...</td>\n",
       "      <td>2013-03-01 19:58:50</td>\n",
       "      <td>WeirdPlane</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "      <td>Could I buy an Android phone without a plan an...</td>\n",
       "      <td>19hblp</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>/r/AskReddit/comments/19hblj/how_do_i_reddit/</td>\n",
       "      <td>Yeah.\n",
       "\n",
       "How do I reddit? I don't use or read re...</td>\n",
       "      <td>http://www.reddit.com/r/AskReddit/comments/19h...</td>\n",
       "      <td>2013-03-01 19:58:47</td>\n",
       "      <td>xxnovaroxgg</td>\n",
       "      <td>14</td>\n",
       "      <td>0</td>\n",
       "      <td>How do I reddit</td>\n",
       "      <td>19hblj</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>/r/AskReddit/comments/19hbjx/xpost_rsurvival_h...</td>\n",
       "      <td>My brothers, dad and I have always been huge L...</td>\n",
       "      <td>http://www.reddit.com/r/AskReddit/comments/19h...</td>\n",
       "      <td>2013-03-01 19:58:07</td>\n",
       "      <td>tuffstough</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>(x-post r/survival) Have any redditors seen Le...</td>\n",
       "      <td>19hbjx</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>/r/AskReddit/comments/19hbjk/female_redditors_...</td>\n",
       "      <td>I'm curious, guys tend to get asked the usual ...</td>\n",
       "      <td>http://www.reddit.com/r/AskReddit/comments/19h...</td>\n",
       "      <td>2013-03-01 19:57:58</td>\n",
       "      <td>redditredditx3</td>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>Female Redditors, which part of the male physi...</td>\n",
       "      <td>19hbjk</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                           permalink  \\\n",
       "0  /r/AskReddit/comments/19hbm0/in_the_way_that_p...   \n",
       "1  /r/AskReddit/comments/19hblp/could_i_buy_an_an...   \n",
       "2      /r/AskReddit/comments/19hblj/how_do_i_reddit/   \n",
       "3  /r/AskReddit/comments/19hbjx/xpost_rsurvival_h...   \n",
       "4  /r/AskReddit/comments/19hbjk/female_redditors_...   \n",
       "\n",
       "                                            selftext  \\\n",
       "0  Basically, do other parts of the world have th...   \n",
       "1                                                      \n",
       "2  Yeah.\n",
       "\n",
       "How do I reddit? I don't use or read re...   \n",
       "3  My brothers, dad and I have always been huge L...   \n",
       "4  I'm curious, guys tend to get asked the usual ...   \n",
       "\n",
       "                                                 url          created_utc  \\\n",
       "0  http://www.reddit.com/r/AskReddit/comments/19h...  2013-03-01 19:58:55   \n",
       "1  http://www.reddit.com/r/AskReddit/comments/19h...  2013-03-01 19:58:50   \n",
       "2  http://www.reddit.com/r/AskReddit/comments/19h...  2013-03-01 19:58:47   \n",
       "3  http://www.reddit.com/r/AskReddit/comments/19h...  2013-03-01 19:58:07   \n",
       "4  http://www.reddit.com/r/AskReddit/comments/19h...  2013-03-01 19:57:58   \n",
       "\n",
       "           author  num_comments  score  \\\n",
       "0           sjr63             1      1   \n",
       "1      WeirdPlane            13      1   \n",
       "2     xxnovaroxgg            14      0   \n",
       "3      tuffstough             0      1   \n",
       "4  redditredditx3            13      2   \n",
       "\n",
       "                                               title      id  downs  ups  \n",
       "0  In the way that popular English and American m...  19hbm0      0    1  \n",
       "1  Could I buy an Android phone without a plan an...  19hblp      0    1  \n",
       "2                                    How do I reddit  19hblj      0    0  \n",
       "3  (x-post r/survival) Have any redditors seen Le...  19hbjx      0    1  \n",
       "4  Female Redditors, which part of the male physi...  19hbjk      0    2  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = submissions_to_dataframe(submissions)\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "518addff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e5490dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "start_date = datetime.strptime(\"2013-01-01\", \"%Y-%m-%d\")\n",
    "start_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf13555a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df[\"created_utc\"] = pd.to_datetime(df[\"created_utc\"], unit=\"s\").dt.tz_localize(\"UTC\").dt.strftime('%Y-%m-%d %H:%M:%S')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48e413f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e83befa",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba84be68",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}