|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "38df9b7b-1835-4ec9-aa00-a85c8b80730e", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import requests\n", |
| 11 | + "import pandas as pd\n", |
| 12 | + "\n", |
| 13 | + "def get_star_history(repo):\n", |
| 14 | + " owner = \"GenericMappingTools\"\n", |
| 15 | + " headers = {\n", |
| 16 | + " \"Accept\": \"application/vnd.github.v3.star+json\",\n", |
| 17 | + " # \"Authorization\": \"Bearer {YOUR_GITHUB_TOKEN_HERE}\",\n", |
| 18 | + " }\n", |
| 19 | + "\n", |
| 20 | + " timestamps, users = [], []\n", |
| 21 | + " page = 1\n", |
| 22 | + " while True:\n", |
| 23 | + " r = requests.get(\n", |
| 24 | + " f\"https://api.github.com/repos/{owner}/{repo}/stargazers\",\n", |
| 25 | + " headers=headers,\n", |
| 26 | + " params={\"per_page\": 100, \"page\": page},\n", |
| 27 | + " )\n", |
| 28 | + " data = r.json()\n", |
| 29 | + " if not data:\n", |
| 30 | + " break\n", |
| 31 | + "\n", |
| 32 | + " timestamps += [s[\"starred_at\"] for s in data] # full ISO 8601 timestamp\n", |
| 33 | + " users += [s[\"user\"][\"login\"] for s in data]\n", |
| 34 | + " page += 1\n", |
| 35 | + " df = pd.DataFrame({\"timestamp\": timestamps, \"user\": users}).sort_values(\"timestamp\")\n", |
| 36 | + " df.to_csv(f\"star_history_github_{repo}.csv\", sep=\",\", index=False)\n", |
| 37 | + "\n", |
| 38 | + "\n", |
| 39 | + "for repo in [\"gmt\", \"pygmt\", \"gmt.jl\", \"gmtmex\"]:\n", |
| 40 | + " get_star_history(repo)" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "id": "2d2a877f-a55c-43a9-bbbb-d9b4df79d057", |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [ |
| 50 | + "import datetime\n", |
| 51 | + "\n", |
| 52 | + "import pandas as pd\n", |
| 53 | + "import pygmt\n", |
| 54 | + "from pygmt.params import Box\n", |
| 55 | + "\n", |
| 56 | + "fig = pygmt.Figure()\n", |
| 57 | + "fig.basemap(\n", |
| 58 | + " projection=\"X12c/6c\",\n", |
| 59 | + " region=[datetime.date(2016, 1, 1), datetime.datetime.now(), -50, 1000],\n", |
| 60 | + " frame=[\"x\", \"ya100f50+lGitHub stars\"],\n", |
| 61 | + ")\n", |
| 62 | + "\n", |
| 63 | + "for wrapper, file, color, symbol in zip(\n", |
| 64 | + " [\"GMT\", \"PyGMT\", \"GMT.jl\", \"GMT/MEX\"],\n", |
| 65 | + " [\"gmt\", \"pygmt\", \"gmt.jl\", \"gmtmex\"],\n", |
| 66 | + " [\"238/86/52\", \"48/105/152\", \"149/88/178\", \"230/51/51\"],\n", |
| 67 | + " [\"C\", \"A\", \"T\", \"I\"],\n", |
| 68 | + " strict=False,\n", |
| 69 | + "):\n", |
| 70 | + " df = pd.read_csv(\n", |
| 71 | + " f\"star_history_github_{file}.csv\",\n", |
| 72 | + " parse_dates=[\"timestamp\"],\n", |
| 73 | + " index_col=\"timestamp\",\n", |
| 74 | + " )\n", |
| 75 | + " df = df.resample(\"6ME\").count().cumsum().rename(columns={\"user\": \"stars\"})\n", |
| 76 | + " fig.plot(x=df.index, y=df[\"stars\"], pen=color)\n", |
| 77 | + " fig.plot(\n", |
| 78 | + " x=df.index, y=df[\"stars\"], style=f\"{symbol}0.2c\", fill=color, label=wrapper\n", |
| 79 | + " )\n", |
| 80 | + "fig.legend(\n", |
| 81 | + " position=\"jTL+o0.1c+w2.3\", box=Box(fill=\"gray95\", pen=\"0.5p,gray50\", radius=\"3p\")\n", |
| 82 | + ")\n", |
| 83 | + "\n", |
| 84 | + "fig.show()\n", |
| 85 | + "# fig.savefig(fname=\"Fig7_PyGMT_datetime.png\")" |
| 86 | + ] |
| 87 | + } |
| 88 | + ], |
| 89 | + "metadata": { |
| 90 | + "kernelspec": { |
| 91 | + "display_name": "Python 3 (ipykernel)", |
| 92 | + "language": "python", |
| 93 | + "name": "python3" |
| 94 | + }, |
| 95 | + "language_info": { |
| 96 | + "codemirror_mode": { |
| 97 | + "name": "ipython", |
| 98 | + "version": 3 |
| 99 | + }, |
| 100 | + "file_extension": ".py", |
| 101 | + "mimetype": "text/x-python", |
| 102 | + "name": "python", |
| 103 | + "nbconvert_exporter": "python", |
| 104 | + "pygments_lexer": "ipython3", |
| 105 | + "version": "3.12.3" |
| 106 | + } |
| 107 | + }, |
| 108 | + "nbformat": 4, |
| 109 | + "nbformat_minor": 5 |
| 110 | +} |
0 commit comments