Datasets:
File size: 12,560 Bytes
1683143 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5f3bbfca",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import requests\n",
"import time\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b82b8cda",
"metadata": {},
"outputs": [],
"source": [
"! mkdir esci_imgs"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e80143a7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1480714 collection-imgs.json\r\n"
]
}
],
"source": [
"! wc -l collection-imgs.json"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a7d602a2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\"doc_id\": 0, \"image_url\": \"https://m.media-amazon.com/images/I/815fXDqFFQL.__AC_SX300_SY300_QL70_ML2_.jpg\"}\r\n",
"{\"doc_id\": 1, \"image_url\": \"https://m.media-amazon.com/images/I/81bdoltQWVL.__AC_SY300_SX300_QL70_FMwebp_.jpg\"}\r\n",
"{\"doc_id\": 2, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T2/images/I/71DqTKVRneL.__AC_SY445_SX342_QL70_FMwebp_.jpg\"}\r\n",
"{\"doc_id\": 3, \"image_url\": \"https://m.media-amazon.com/images/I/819OiK-OD6L.__AC_SY445_SX342_QL70_ML2_.jpg\"}\r\n",
"{\"doc_id\": 4, \"image_url\": \"https://m.media-amazon.com/images/I/61NemNt5X6L.__AC_SX300_SY300_QL70_ML2_.jpg\"}\r\n",
"{\"doc_id\": 6, \"image_url\": \"https://m.media-amazon.com/images/I/41On0AlK82L.__AC_SX300_SY300_QL70_FMwebp_.jpg\"}\r\n",
"{\"doc_id\": 7, \"image_url\": \"\"}\r\n",
"{\"doc_id\": 9, \"image_url\": \"\"}\r\n",
"{\"doc_id\": 10, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T1/images/I/813GQqEX9UL.__AC_SX300_SY300_QL70_FMwebp_.jpg\"}\r\n",
"{\"doc_id\": 11, \"image_url\": \"https://m.media-amazon.com/images/W/WEBP_402378-T1/images/I/71qbCHQo2vL.__AC_SY445_SX342_QL70_FMwebp_.jpg\"}\r\n"
]
}
],
"source": [
"! head collection-imgs.json"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "146b3a26",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1480714\n"
]
}
],
"source": [
"id2imgurl = {}\n",
"with open('collection-imgs.json','r') as f:\n",
" for l in f:\n",
" j = json.loads(l)\n",
" id2imgurl[j['doc_id']] = j['image_url']\n",
"print(len(id2imgurl))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "693fb9ce",
"metadata": {},
"outputs": [],
"source": [
"target_url = id2imgurl[2]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "093e563c",
"metadata": {},
"outputs": [],
"source": [
"img_data = requests.get(target_url).content\n",
"with open('esci_imgs/' + str(2) + '.jpg', 'wb') as handler:\n",
" handler.write(img_data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11aa2665",
"metadata": {},
"outputs": [],
"source": [
"! ls esci_imgs | wc -l"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fac1d815",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Succefully downloaded 0 Images\n",
"UnSuccefully downloaded 0 Images\n",
"Succefully downloaded 888 Images\n",
"UnSuccefully downloaded 112 Images\n",
"Succefully downloaded 1772 Images\n",
"UnSuccefully downloaded 228 Images\n",
"Succefully downloaded 2648 Images\n",
"UnSuccefully downloaded 352 Images\n",
"Succefully downloaded 3543 Images\n",
"UnSuccefully downloaded 457 Images\n",
"Succefully downloaded 4430 Images\n",
"UnSuccefully downloaded 570 Images\n",
"Succefully downloaded 5299 Images\n",
"UnSuccefully downloaded 701 Images\n",
"Succefully downloaded 6177 Images\n",
"UnSuccefully downloaded 823 Images\n",
"Succefully downloaded 7066 Images\n",
"UnSuccefully downloaded 934 Images\n",
"Succefully downloaded 7950 Images\n",
"UnSuccefully downloaded 1050 Images\n",
"Succefully downloaded 8825 Images\n",
"UnSuccefully downloaded 1175 Images\n",
"Succefully downloaded 9724 Images\n",
"UnSuccefully downloaded 1276 Images\n",
"Succefully downloaded 10607 Images\n",
"UnSuccefully downloaded 1393 Images\n",
"Succefully downloaded 11495 Images\n",
"UnSuccefully downloaded 1505 Images\n",
"Succefully downloaded 12393 Images\n",
"UnSuccefully downloaded 1607 Images\n",
"Succefully downloaded 13279 Images\n",
"UnSuccefully downloaded 1721 Images\n",
"Succefully downloaded 14181 Images\n",
"UnSuccefully downloaded 1819 Images\n",
"Succefully downloaded 15046 Images\n",
"UnSuccefully downloaded 1954 Images\n",
"Succefully downloaded 15917 Images\n",
"UnSuccefully downloaded 2083 Images\n",
"Succefully downloaded 16796 Images\n",
"UnSuccefully downloaded 2204 Images\n",
"Succefully downloaded 17663 Images\n",
"UnSuccefully downloaded 2337 Images\n",
"Succefully downloaded 18546 Images\n",
"UnSuccefully downloaded 2454 Images\n",
"Succefully downloaded 19442 Images\n",
"UnSuccefully downloaded 2558 Images\n",
"Succefully downloaded 20312 Images\n",
"UnSuccefully downloaded 2688 Images\n",
"Succefully downloaded 21198 Images\n",
"UnSuccefully downloaded 2802 Images\n",
"Succefully downloaded 22083 Images\n",
"UnSuccefully downloaded 2917 Images\n",
"Succefully downloaded 22973 Images\n",
"UnSuccefully downloaded 3027 Images\n",
"Succefully downloaded 23860 Images\n",
"UnSuccefully downloaded 3140 Images\n",
"Succefully downloaded 24744 Images\n",
"UnSuccefully downloaded 3256 Images\n",
"Succefully downloaded 25635 Images\n",
"UnSuccefully downloaded 3365 Images\n",
"Succefully downloaded 26524 Images\n",
"UnSuccefully downloaded 3476 Images\n",
"Succefully downloaded 27404 Images\n",
"UnSuccefully downloaded 3596 Images\n",
"Succefully downloaded 28282 Images\n",
"UnSuccefully downloaded 3718 Images\n",
"Succefully downloaded 29156 Images\n",
"UnSuccefully downloaded 3844 Images\n",
"Succefully downloaded 30046 Images\n",
"UnSuccefully downloaded 3954 Images\n",
"Succefully downloaded 30943 Images\n",
"UnSuccefully downloaded 4057 Images\n",
"Succefully downloaded 31806 Images\n",
"UnSuccefully downloaded 4194 Images\n",
"Succefully downloaded 32686 Images\n",
"UnSuccefully downloaded 4314 Images\n",
"Succefully downloaded 33576 Images\n",
"UnSuccefully downloaded 4424 Images\n",
"Succefully downloaded 34469 Images\n",
"UnSuccefully downloaded 4531 Images\n",
"Succefully downloaded 35349 Images\n",
"UnSuccefully downloaded 4651 Images\n",
"Succefully downloaded 36232 Images\n",
"UnSuccefully downloaded 4768 Images\n",
"Succefully downloaded 37113 Images\n",
"UnSuccefully downloaded 4887 Images\n",
"Succefully downloaded 37993 Images\n",
"UnSuccefully downloaded 5007 Images\n",
"Succefully downloaded 38866 Images\n",
"UnSuccefully downloaded 5134 Images\n",
"Succefully downloaded 39752 Images\n",
"UnSuccefully downloaded 5248 Images\n",
"Succefully downloaded 40646 Images\n",
"UnSuccefully downloaded 5354 Images\n",
"Succefully downloaded 41535 Images\n",
"UnSuccefully downloaded 5465 Images\n",
"Succefully downloaded 42421 Images\n",
"UnSuccefully downloaded 5579 Images\n",
"Succefully downloaded 43313 Images\n",
"UnSuccefully downloaded 5687 Images\n",
"Succefully downloaded 44177 Images\n",
"UnSuccefully downloaded 5823 Images\n",
"Succefully downloaded 45057 Images\n",
"UnSuccefully downloaded 5943 Images\n",
"Succefully downloaded 45933 Images\n",
"UnSuccefully downloaded 6067 Images\n",
"Succefully downloaded 46810 Images\n",
"UnSuccefully downloaded 6190 Images\n",
"Succefully downloaded 47697 Images\n",
"UnSuccefully downloaded 6303 Images\n",
"Succefully downloaded 48579 Images\n",
"UnSuccefully downloaded 6421 Images\n",
"Succefully downloaded 49449 Images\n",
"UnSuccefully downloaded 6551 Images\n",
"Succefully downloaded 50330 Images\n",
"UnSuccefully downloaded 6670 Images\n",
"Succefully downloaded 51235 Images\n",
"UnSuccefully downloaded 6765 Images\n",
"Succefully downloaded 52113 Images\n",
"UnSuccefully downloaded 6887 Images\n",
"Succefully downloaded 52999 Images\n",
"UnSuccefully downloaded 7001 Images\n",
"Succefully downloaded 53877 Images\n",
"UnSuccefully downloaded 7123 Images\n",
"Succefully downloaded 54776 Images\n",
"UnSuccefully downloaded 7224 Images\n",
"Succefully downloaded 55646 Images\n",
"UnSuccefully downloaded 7354 Images\n",
"Succefully downloaded 56530 Images\n",
"UnSuccefully downloaded 7470 Images\n",
"Succefully downloaded 57423 Images\n",
"UnSuccefully downloaded 7577 Images\n",
"Succefully downloaded 58300 Images\n",
"UnSuccefully downloaded 7700 Images\n",
"Succefully downloaded 59205 Images\n",
"UnSuccefully downloaded 7795 Images\n",
"Succefully downloaded 60084 Images\n",
"UnSuccefully downloaded 7916 Images\n",
"Succefully downloaded 60990 Images\n",
"UnSuccefully downloaded 8010 Images\n",
"Succefully downloaded 61888 Images\n",
"UnSuccefully downloaded 8112 Images\n",
"Succefully downloaded 62786 Images\n",
"UnSuccefully downloaded 8214 Images\n",
"Succefully downloaded 63662 Images\n",
"UnSuccefully downloaded 8338 Images\n",
"Succefully downloaded 64559 Images\n",
"UnSuccefully downloaded 8441 Images\n",
"Succefully downloaded 65441 Images\n",
"UnSuccefully downloaded 8559 Images\n",
"Succefully downloaded 66332 Images\n",
"UnSuccefully downloaded 8668 Images\n",
"Succefully downloaded 67216 Images\n",
"UnSuccefully downloaded 8784 Images\n",
"Succefully downloaded 68077 Images\n",
"UnSuccefully downloaded 8923 Images\n",
"Succefully downloaded 68968 Images\n",
"UnSuccefully downloaded 9032 Images\n",
"Succefully downloaded 69852 Images\n",
"UnSuccefully downloaded 9148 Images\n",
"Succefully downloaded 70744 Images\n",
"UnSuccefully downloaded 9256 Images\n",
"Succefully downloaded 71625 Images\n",
"UnSuccefully downloaded 9375 Images\n",
"Succefully downloaded 72518 Images\n",
"UnSuccefully downloaded 9482 Images\n",
"Succefully downloaded 73403 Images\n",
"UnSuccefully downloaded 9597 Images\n"
]
}
],
"source": [
"missed_list = []\n",
"hit_list = []\n",
"count = 0\n",
"for i in id2imgurl:\n",
" if count % 100 == 0:\n",
" time.sleep(1)\n",
" if count % 1000 == 0:\n",
" print(\"Succefully downloaded {} Images\".format(len(hit_list)))\n",
" print(\"UnSuccefully downloaded {} Images\".format(len(missed_list)))\n",
" target_url = id2imgurl[i]\n",
" count += 1\n",
" try:\n",
" img_data = requests.get(target_url).content\n",
" with open('esci_imgs/' + str(i) + '.jpg', 'wb') as handler:\n",
" handler.write(img_data)\n",
" hit_list.append(i)\n",
" except:\n",
" missed_list.append(i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "51271307",
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|