File size: 11,179 Bytes
821537b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "460d90da-b986-4c1c-8a66-eab144b0ba8d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n",
      "Fetched data for all the Pages.\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import time\n",
    "\n",
    "import random\n",
    "pages = [\n",
    "            random.randint(1, 968000015)\n",
    "            for _ in range(10)\n",
    "        ]\n",
    "# print(pages)\n",
    "\n",
    "base_url = \"https://datasets-server.huggingface.co/rows\"\n",
    "params = {\n",
    "            \"dataset\": \"tiiuae/falcon-refinedweb\",\n",
    "            \"config\": \"default\",\n",
    "            \"split\": \"train\",\n",
    "        }\n",
    "# response = requests.get(base_url, params=params)\n",
    "# response.raise_for_status()\n",
    "# for row in response.json()[\"rows\"]:\n",
    "#   content = row[\"row\"][\"content\"]\n",
    "num_rows_per_page = 100\n",
    "retry_limit = 10\n",
    "retry_delay = 5\n",
    "Falcon = []\n",
    "\n",
    "def fetch_data_for_page(page):\n",
    "        params[\"offset\"] = page\n",
    "        params[\"limit\"] = num_rows_per_page\n",
    "        attempt = 0\n",
    "        while attempt < retry_limit:\n",
    "            try:\n",
    "                response = requests.get(base_url, params=params)\n",
    "                response.raise_for_status()  # This will raise an HTTPError if the HTTP request returned an unsuccessful status code\n",
    "                for row in response.json()[\"rows\"]:\n",
    "                    content = row[\"row\"][\"content\"]\n",
    "                    Falcon.append(content)\n",
    "                len(Falcon)\n",
    "                print(f\"Fetched data for all the Pages.\")\n",
    "                break\n",
    "            except requests.exceptions.HTTPError as e:\n",
    "                attempt += 1\n",
    "                print(\n",
    "                    f\"Failed to fetch data, retrying. Attempt {attempt}/{retry_limit}\"\n",
    "                )\n",
    "                if attempt < retry_limit:\n",
    "                    time.sleep(retry_delay)  # Wait before the next retry\n",
    "                else:\n",
    "                    print(\n",
    "                        \"Maximum retry limit reached. Unable to fetch data.\"\n",
    "                    )\n",
    "                    raise\n",
    "\n",
    "for page in pages:\n",
    "  fetch_data_for_page(page)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f8f3baf1-5480-450b-a456-174a5c114d3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "\n",
    "# Open the CSV file for writing\n",
    "with open(\"FalconDataEval2.csv\", \"w\", newline=\"\") as csvfile:\n",
    "    # Create a CSV writer object\n",
    "    writer = csv.writer(csvfile)\n",
    "\n",
    "    # Write the header row\n",
    "    writer.writerow([\"Text\"])\n",
    "\n",
    "    # Write each element in the list as a row in the CSV file\n",
    "    for element in Falcon:\n",
    "        writer.writerow([element])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ea47c936-2c2b-4414-ba57-74fb6827ec0a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of duplicate rows: 0\n",
      "Empty DataFrame\n",
      "Columns: [Text]\n",
      "Index: []\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "# Read the CSV file into a pandas DataFrame\n",
    "df = pd.read_csv(\"FalconDataEval2.csv\")\n",
    "\n",
    "# Check for duplicate rows\n",
    "duplicate_rows = df[df.duplicated()]\n",
    "\n",
    "# Print the number of duplicate rows\n",
    "print(f\"Number of duplicate rows: {len(duplicate_rows)}\")\n",
    "\n",
    "# Print the duplicate rows\n",
    "print(duplicate_rows)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f4178cd6-747f-4e05-a9bf-17b97f959e06",
   "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>Text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Our Annual Garden Party is a fun-filled event ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Photos by Philip Cosores\\n“There were many poi...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Media Matters Also Wants To Throw Out The Firs...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>[More]\\nWhile bringing in your own cup is fine...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Read at : Google Alert – gardening\\nHow to Bui...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                Text\n",
       "0  Our Annual Garden Party is a fun-filled event ...\n",
       "1  Photos by Philip Cosores\\n“There were many poi...\n",
       "2  Media Matters Also Wants To Throw Out The Firs...\n",
       "3  [More]\\nWhile bringing in your own cup is fine...\n",
       "4  Read at : Google Alert – gardening\\nHow to Bui..."
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "264548c1-4cf4-441f-a433-2f5d57861dc4",
   "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>Text</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>The Ketologic review Diaries\\nShould you have ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>A pack of hand cooked sea salted and red wine ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>この広告は、90日以上更新していないブログに表示しています。\\nsniperspy free...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>Arthur Koestler - Wikipedia.\\nEssay - Merriam-...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>Serving Software Downloads in 976 Categories, ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                  Text\n",
       "995  The Ketologic review Diaries\\nShould you have ...\n",
       "996  A pack of hand cooked sea salted and red wine ...\n",
       "997  この広告は、90日以上更新していないブログに表示しています。\\nsniperspy free...\n",
       "998  Arthur Koestler - Wikipedia.\\nEssay - Merriam-...\n",
       "999  Serving Software Downloads in 976 Categories, ..."
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "be5a87a8-cfee-4f63-992e-8fa1d4a5cdbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text    To imagine delaying myself. Hard cock, selling...\n",
       "Name: 48, dtype: object"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "target_row=48\n",
    "specific_row = df.iloc[target_row]\n",
    "specific_row"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e97d9e18-eaa0-4a1b-96ab-c89a0f4c738d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Text    The old wireline Bell telephone system was bui...\n",
      "Name: 19995, dtype: object\n"
     ]
    }
   ],
   "source": [
    "print(specific_row)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "940ef35f-7517-403d-9f42-73760182dcaa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Text    The old wireline Bell telephone system was bui...\n"
     ]
    }
   ],
   "source": [
    "print(specific_row.to_string())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "915ac669-718f-47f5-b175-a5f928b407db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "57\n"
     ]
    }
   ],
   "source": [
    "print(len(specific_row.to_string()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab5ee254-9ba7-496b-97c7-3b6185c21971",
   "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.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}