{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"To update `pypi_10k_most_dependents.txt`, enter your `api_key` from https://libraries.io/account.\n",
    "\n",
    "The latest version is available at: https://gist.github.com/charliermarsh/07afd9f543dfea68408a4a42cede4be4.\n",
    "\"\"\"\n",
    "\n",
    "import httpx\n",
    "\n",
    "from pathlib import Path\n",
    "\n",
    "api_key = \"\"\n",
    "responses = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2532bf8c426af5",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "for i in range(100): # 100 pages with 100 per page -> 10k\n",
    "    print(i)\n",
    "    if not i in responses:\n",
    "        # https://libraries.io/api#project-search\n",
    "        sort = \"dependents_count\"\n",
    "        url = f\"https://libraries.io/api/search?platforms=Pypi&per_page=100&page={i+1}&sort{sort}&api_key={api_key}\"\n",
    "        responses[i] = httpx.get(url, timeout=30.0).json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7bc80702b6f8ebc3",
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    }
   },
   "outputs": [],
   "source": [
    "flat_list = []\n",
    "for response in responses.values():\n",
    "    for entry in response:\n",
    "        flat_list.append(entry[\"name\"])\n",
    "print(flat_list)\n",
    "Path().parent.joinpath(\"pypi_10k_most_dependents.txt\").write_text(\"\\n\".join(flat_list))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
