{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# Headshots\n",
    "\n",
    "`headshot_url` builds a player headshot url from an id. ESPN athlete ids work directly; other id systems are\n",
    "translated through a table (for NFL, nflverse's gsis ids)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sdvplot"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2",
   "metadata": {},
   "source": [
    "## Headshot urls\n",
    "\n",
    "An ESPN athlete id works as is; an NFL gsis id goes through the nflverse player table."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "sdvplot.headshot_url(3139477, \"nfl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [],
   "source": [
    "sdvplot.headshot_url(\"00-0033873\", \"nfl\", id_system=\"gsis\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "## Show a headshot\n",
    "\n",
    "The url is an ordinary image link. Here the gsis one is downloaded and shown."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import io\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "import requests\n",
    "from PIL import Image\n",
    "\n",
    "url = sdvplot.headshot_url(\"00-0033873\", \"nfl\", id_system=\"gsis\")\n",
    "img = Image.open(io.BytesIO(requests.get(url, timeout=30).content))\n",
    "plt.imshow(img)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "## Other leagues\n",
    "\n",
    "Other leagues use their ESPN athlete id the same way, for example a men's college basketball player:\n",
    "\n",
    "```python\n",
    "sdvplot.headshot_url(4433134, \"mbb\")\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "sdvplot": {
   "description": "Build player headshot urls from ESPN athlete ids and NFL gsis ids, and show one in matplotlib.",
   "label": "Headshots",
   "position": 4
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
