{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Get images\n", "\n", "This is because I'm really lazy and copying and pasteing into jupyter notebooks is less than fun when the images already exist in the outside world.... 😂\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6a9f2ad25a3f43578564e238992a56ea", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(FloatProgress(value=0.0, max=5.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "\n", "import requests\n", "import json\n", "from pathlib import Path\n", "from tqdm.auto import tqdm\n", "\n", "target = Path('img')\n", "source = Path('images.json')\n", "\n", "def get_image(url,name):\n", " r = requests.get(url)\n", " r.raise_for_status()\n", " (target/name).write_bytes(r.content)\n", " return True\n", "\n", "\n", "images = json.loads(source.read_text())\n", "for url,name in tqdm(images.items()):\n", " get_image(url,name)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'https://i.redd.it/c14oontjoop21.png': 'math_skill.png',\n", " 'https://i.imgur.com/XJyemeI.jpg': 'great_success.jpg',\n", " 'https://miro.medium.com/max/700/0*b3jEIVWk_m0_J9jH.png': 'arrow_mem.png',\n", " 'https://i0.wp.com/nerdarchy.com/wp-content/uploads/2019/03/izzet-league.png': 'artificer.png'}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "images" ] }, { "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }