Spaces:
Runtime error
Runtime error
File size: 17,533 Bytes
8e9a7ea 7688b91 8e9a7ea f66e0ee 8e9a7ea f66e0ee 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea 7688b91 8e9a7ea f66e0ee 8e9a7ea |
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import praw\n",
"import pandas as pd\n",
"from Keys import reddit_keys\n",
"\n",
"reddit= praw.Reddit(client_id=reddit_keys['client_id'],\t\t # your client id\n",
"\t\t\t\t\tclient_secret=reddit_keys['client_secret'],\t # your client secret\n",
" usernme = reddit_keys['usernme'], #profile username\n",
" password = reddit_keys['password'], #profile password\n",
"\t\t\t\t\tuser_agent=reddit_keys['user_agent'])\t # your user agent\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from praw.models import MoreComments\n",
"from transformers import pipeline\n",
"from transformers import DistilBertTokenizerFast\n",
"classifier = pipeline(\"sentiment-analysis\", model=\"michellejieli/NSFW_text_classifier\")\n",
"\n",
"input_url = \"https://www.reddit.com/r/europe/comments/r0hthg/sweden_is_taking_the_lead_to_persuade_the_rest_of/\"\n",
"\n",
"def extract_comments(input_url):\n",
" submission = reddit.submission(url=input_url)\n",
" #posts_dict = {\"Post text\":[],}\n",
" posts_dict = {\"Post text\":[], \"class\": []}\n",
" for top_level_comment in submission.comments:\n",
" if isinstance(top_level_comment, MoreComments):\n",
" continue\n",
" \n",
" posts_dict[\"Post text\"].append(top_level_comment.body)\n",
" posts_dict[\"class\"].append(classifier(top_level_comment.body)[0]['label'])\n",
" df = pd.DataFrame(posts_dict)\n",
" return df "
]
},
{
"cell_type": "code",
"execution_count": 9,
"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>Post text</th>\n",
" <th>class</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Does… does that mean GPU’s might become afford...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>But I use my mining rig for interior heating. ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>I approve.\\n\\nAlthough have they suggested how...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>You can't ban cryptocurrencies. Just like you ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>But still no nuclear plants</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>https://twitter.com/ercwl/status/1457114531314...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>Yes, \"we\" are missing the goal. Maybe stop sub...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>here is something complete insane to think abo...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>Put a tax carbon on it, it will elimanate the ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Banning crypto mining will only cause it to mo...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>Can someone explain how this is possible?</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>The average knowledge on crypto in here is ver...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>Howbout u ban Facebook instead?</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>Good. Blockchain is useful but so many despera...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>I don't particularly like crypto or it's fans,...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>I was thinking of getting rid of my RTX 2070s,...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>Total waste of time. As seen following the Chi...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>It's actually shocking how uneducated people a...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>Totally doesn’t have anything to do with money...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>Sweden's biggest electric company Vattenfall s...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>BASED</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>Excellent news.\\n\\nIt consumes vast quantities...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>sweden want to fuck with danemark and his cryp...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>They should ban gold too, mining gold uses 10x...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>Great news. Cryptocurrencies are an embarrassi...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25</th>\n",
" <td>This is BS, it doesn't make sense.</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>26</th>\n",
" <td>I see no problem with this, the amount of ener...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>27</th>\n",
" <td>[deleted]</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>28</th>\n",
" <td>\"I'm running my graphics card at full load so ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>29</th>\n",
" <td>The market is moving from POW to POS which is ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>30</th>\n",
" <td>And exactly how are they gonna do that?\\n\\nPir...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>31</th>\n",
" <td>Yeah because that's what's the main cause of o...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>32</th>\n",
" <td>Banning mining without banning transactions an...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>33</th>\n",
" <td>Crypto seems to have some side effects, who wo...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>34</th>\n",
" <td>Crypto currency is the new tulips. So hot righ...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>35</th>\n",
" <td>Fuck yeah, ban them all! Easiest climate check...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>36</th>\n",
" <td>Ban fossil fuels instead. What a useless measu...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>37</th>\n",
" <td>Please no. I earn 200 euros a month from it.</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>38</th>\n",
" <td>Swedens state owned power company rejects this...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>39</th>\n",
" <td>Great not only we had Chinese crypto miners se...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40</th>\n",
" <td>Let's ban the currency that is somewhat indepe...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>41</th>\n",
" <td>Is that really that much of a problem with ene...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>42</th>\n",
" <td>How about instead of banning it, we make it so...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>43</th>\n",
" <td>The electric footprint of crypto won't go up. ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>44</th>\n",
" <td>Lets make playing a demanding game more than t...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>45</th>\n",
" <td>How does cryptocurrency change the climate? I ...</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>46</th>\n",
" <td>Load ze Sweden FUD</td>\n",
" <td>SFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>47</th>\n",
" <td>[removed]</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>48</th>\n",
" <td>Such pathetic virtue-signaling.\\n\\nIts no diff...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>49</th>\n",
" <td>shame on sweden</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50</th>\n",
" <td>-And now, NEWS FOR DUMBASSES, Bob?\\n\\n-Yes Bri...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>51</th>\n",
" <td>dumb</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>52</th>\n",
" <td>Wow, Sweden is such a dictatorial shithole cou...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" <tr>\n",
" <th>53</th>\n",
" <td>talking about that, a full ban might be unlike...</td>\n",
" <td>NSFW</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Post text class\n",
"0 Does… does that mean GPU’s might become afford... SFW\n",
"1 But I use my mining rig for interior heating. ... SFW\n",
"2 I approve.\\n\\nAlthough have they suggested how... SFW\n",
"3 You can't ban cryptocurrencies. Just like you ... SFW\n",
"4 But still no nuclear plants SFW\n",
"5 https://twitter.com/ercwl/status/1457114531314... NSFW\n",
"6 Yes, \"we\" are missing the goal. Maybe stop sub... NSFW\n",
"7 here is something complete insane to think abo... NSFW\n",
"8 Put a tax carbon on it, it will elimanate the ... SFW\n",
"9 Banning crypto mining will only cause it to mo... SFW\n",
"10 Can someone explain how this is possible? SFW\n",
"11 The average knowledge on crypto in here is ver... NSFW\n",
"12 Howbout u ban Facebook instead? NSFW\n",
"13 Good. Blockchain is useful but so many despera... NSFW\n",
"14 I don't particularly like crypto or it's fans,... SFW\n",
"15 I was thinking of getting rid of my RTX 2070s,... SFW\n",
"16 Total waste of time. As seen following the Chi... SFW\n",
"17 It's actually shocking how uneducated people a... NSFW\n",
"18 Totally doesn’t have anything to do with money... NSFW\n",
"19 Sweden's biggest electric company Vattenfall s... NSFW\n",
"20 BASED SFW\n",
"21 Excellent news.\\n\\nIt consumes vast quantities... NSFW\n",
"22 sweden want to fuck with danemark and his cryp... NSFW\n",
"23 They should ban gold too, mining gold uses 10x... NSFW\n",
"24 Great news. Cryptocurrencies are an embarrassi... NSFW\n",
"25 This is BS, it doesn't make sense. NSFW\n",
"26 I see no problem with this, the amount of ener... SFW\n",
"27 [deleted] SFW\n",
"28 \"I'm running my graphics card at full load so ... SFW\n",
"29 The market is moving from POW to POS which is ... SFW\n",
"30 And exactly how are they gonna do that?\\n\\nPir... SFW\n",
"31 Yeah because that's what's the main cause of o... SFW\n",
"32 Banning mining without banning transactions an... NSFW\n",
"33 Crypto seems to have some side effects, who wo... SFW\n",
"34 Crypto currency is the new tulips. So hot righ... NSFW\n",
"35 Fuck yeah, ban them all! Easiest climate check... NSFW\n",
"36 Ban fossil fuels instead. What a useless measu... NSFW\n",
"37 Please no. I earn 200 euros a month from it. SFW\n",
"38 Swedens state owned power company rejects this... NSFW\n",
"39 Great not only we had Chinese crypto miners se... SFW\n",
"40 Let's ban the currency that is somewhat indepe... NSFW\n",
"41 Is that really that much of a problem with ene... NSFW\n",
"42 How about instead of banning it, we make it so... SFW\n",
"43 The electric footprint of crypto won't go up. ... SFW\n",
"44 Lets make playing a demanding game more than t... NSFW\n",
"45 How does cryptocurrency change the climate? I ... SFW\n",
"46 Load ze Sweden FUD SFW\n",
"47 [removed] NSFW\n",
"48 Such pathetic virtue-signaling.\\n\\nIts no diff... NSFW\n",
"49 shame on sweden NSFW\n",
"50 -And now, NEWS FOR DUMBASSES, Bob?\\n\\n-Yes Bri... NSFW\n",
"51 dumb NSFW\n",
"52 Wow, Sweden is such a dictatorial shithole cou... NSFW\n",
"53 talking about that, a full ban might be unlike... NSFW"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
"extract_comments(input_url)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.4 (main, Nov 29 2022, 20:00:25) [GCC 9.4.0]"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "3ad933181bd8a04b432d3370b9dc3b0662ad032c4dfaa4e4f1596c548f763858"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|