{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fastcore.utils import *\n",
    "from fastcore.foundation import *\n",
    "\n",
    "from bs4 import BeautifulSoup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "hooks_url = 'https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads'\n",
    "soup = BeautifulSoup(urlread(hooks_url))\n",
    "events = L(soup.select('li.ml-0')).attrgot('text')[1:]\n",
    "# As at 2020/01/12 the 'sponsor' event has two examples\n",
    "sponsor_evt = events.argwhere(lambda o: o.startswith('sponsor'))[0]\n",
    "elems = L(soup.select('div.height-constrained-code-block > pre:nth-child(1) > code:nth-child(1)')).attrgot('text')\n",
    "# Delete the 2nd sponsor example\n",
    "del(elems[sponsor_evt+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "exs = Path('.')\n",
    "for ev,el in zip(events,elems): (exs/f'{ev}.json').write_text(el)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
