Skip to content

Instantly share code, notes, and snippets.

@astrojuanlu
Last active December 28, 2015 21:19
Show Gist options
  • Select an option

  • Save astrojuanlu/7563926 to your computer and use it in GitHub Desktop.

Select an option

Save astrojuanlu/7563926 to your computer and use it in GitHub Desktop.
GitHub API v3 issue. The returned commits depend on the limiting dates.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:4deae5bf7a285baace185bde84b70061f6c13793432b599e2f371ce042292a58"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import os\n",
"import json\n",
"from datetime import datetime\n",
"\n",
"import requests\n",
"import re\n",
"\n",
"user = \"juanlu001\"\n",
"password = os.environ.get('GITHUB_PASSWORD')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def load_commits(since, until, author=None):\n",
" auth = user, password\n",
" if author:\n",
" base_url = \"https://api.github.com/repos/{}/{}/commits?since={}&until={}&author={}\".format(\n",
" \"matplotlib\", \"matplotlib\", since, until, author)\n",
" else:\n",
" base_url = \"https://api.github.com/repos/{}/{}/commits?since={}&until={}\".format(\n",
" \"matplotlib\", \"matplotlib\", since, until)\n",
" link_p = re.compile('<(.+?)>; rel=\"(first|next|prev)\"')\n",
" res = requests.get(base_url, auth=auth)\n",
" res_obj = json.loads(res.text)\n",
" \n",
" for i in range(10):\n",
" if 'Link' in res.headers:\n",
" links = res.headers['Link'].split(', ')\n",
" for link in links:\n",
" url_link, kind = link_p.match(link).groups()\n",
" if kind == 'next':\n",
" url_next = url_link\n",
" break\n",
" else:\n",
" continue\n",
" res = requests.get(url_next, auth=auth)\n",
" res_obj += json.loads(res.text)\n",
" return res_obj"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data1 = load_commits(\"2013-10-01T00:00:00Z\", \"2013-10-11T00:00:00Z\", \"NelleV\")\n",
"for c in data1:\n",
" if c['author']:\n",
" if c['author']['login'] == \"NelleV\":\n",
" print(c['sha'][:10], c['author']['login'], c['commit']['committer']['date'], c['commit']['message'].split('\\n')[0][:60])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"26498aa247 NelleV 2013-10-09T11:24:06Z Merge pull request #2491 from pelson/pep8_re-enable\n",
"0fab5a7eba NelleV 2013-10-08T13:57:43Z Merge pull request #2502 from pelson/gca_doc\n",
"1129d9c6b0 NelleV 2013-10-02T08:19:46Z ENH better error message when wrong cmap name.\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data2 = load_commits(\"2013-10-01T00:00:00Z\", \"2013-10-11T00:00:00Z\")\n",
"for c in data2:\n",
" if c['author']:\n",
" if c['author']['login'] == \"NelleV\":\n",
" print(c['sha'][:10], c['author']['login'], c['commit']['committer']['date'], c['commit']['message'].split('\\n')[0])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"26498aa247 NelleV 2013-10-09T11:24:06Z Merge pull request #2491 from pelson/pep8_re-enable\n",
"0fab5a7eba NelleV 2013-10-08T13:57:43Z Merge pull request #2502 from pelson/gca_doc\n",
"1129d9c6b0 NelleV 2013-10-02T08:19:46Z ENH better error message when wrong cmap name.\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data3 = load_commits(\"2013-10-01T00:00:00Z\", \"2013-11-01T00:00:00Z\")\n",
"for c in data3:\n",
" if c['author']:\n",
" if c['author']['login'] == \"NelleV\":\n",
" print(c['sha'][:10], c['author']['login'], c['commit']['committer']['date'], c['commit']['message'].split('\\n')[0])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"26498aa247 NelleV 2013-10-09T11:24:06Z Merge pull request #2491 from pelson/pep8_re-enable\n",
"0fab5a7eba NelleV 2013-10-08T13:57:43Z Merge pull request #2502 from pelson/gca_doc\n",
"1129d9c6b0 NelleV 2013-10-02T08:19:46Z ENH better error message when wrong cmap name.\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data4 = load_commits(\"2013-10-01T00:00:00Z\", \"2013-11-01T00:00:00Z\", \"NelleV\")\n",
"for c in data4:\n",
" if c['author']:\n",
" if c['author']['login'] == \"NelleV\":\n",
" print(c['sha'][:10], c['author']['login'], c['commit']['committer']['date'], c['commit']['message'].split('\\n')[0])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"26498aa247 NelleV 2013-10-09T11:24:06Z Merge pull request #2491 from pelson/pep8_re-enable\n",
"0fab5a7eba NelleV 2013-10-08T13:57:43Z Merge pull request #2502 from pelson/gca_doc\n",
"1129d9c6b0 NelleV 2013-10-02T08:19:46Z ENH better error message when wrong cmap name.\n"
]
}
],
"prompt_number": 6
}
],
"metadata": {}
}
]
}
@astrojuanlu
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment