- Initialize the idea as a Gist readme
- Clone the repository locally with just the readme
- Create a new notebook in the repository
- Use notebook to create visualizations
- Create
index.html
to host on blocks through the notebook - Use GitPython API to commit changes.
Last active
August 29, 2015 14:27
-
-
Save ICBacon/ef26d19581d6833ac80d to your computer and use it in GitHub Desktop.
My forked gists and a brand new gist, nbviewer, and bl.ocks workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"> APIless list of forked gists" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"ename": "ImportError", | |
"evalue": "No module named git", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-7-1b33e0257c49>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mIPython\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisplay\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mHTML\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mgit\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mImportError\u001b[0m: No module named git" | |
] | |
} | |
], | |
"source": [ | |
"from pyquery import PyQuery as pq\n", | |
"import requests\n", | |
"import pandas as pd\n", | |
"from IPython.display import HTML\n", | |
"import git" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<table><tr><th>User</th><th>description</th></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/3e84770552501388392d\" target=\"_blank\">My starred gists and a brand new gist, nbviewer, and bl.ocks workflow http://bl.ocks.org/tonyfast/raw/1e1bc45d17020fba5148/</a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/7987c5c066bc8a14e384\" target=\"_blank\"></a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/2e3742b04d7b4b89fbb0\" target=\"_blank\">Studying Color with Bokeh and Grapefruit http://nbviewer.ipython.org/gist/tonyfast/fae0eacea79bbd28996d/ColorStudyGrapefruit.ipynb</a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/5da105c8581876d46b20\" target=\"_blank\"></a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/9325153c88d850adffd0\" target=\"_blank\">Accessing Old Gists</a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/a86b9bb1af0eb3f5511b\" target=\"_blank\"></a></td></tr><tr><td>ICBacon</td><td><a href=\"https://gist.github.com/ICBacon/a61035e05ee842cda5fe\" target=\"_blank\"></a></td></tr></table>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"html, page_number, num_gist = [ '',1,10]\n", | |
"while num_gist == 10:\n", | |
" response = requests.get( url = 'https://gist.github.com/ICBacon/forked', params = { 'page': page_number, },)\n", | |
" gists = pq( response.text )('.gist-snippet')\n", | |
" num_gist, page_number = [ len(pq( response.text )('.gist-snippet')), page_number + 1]\n", | |
" for snippet in gists.items():\n", | |
" t = {\n", | |
" 'author': snippet('.creator > a:first').text(),\n", | |
" 'url': 'https://gist.github.com' + snippet('.creator > a:last').attr['href'],\n", | |
" 'description': snippet('.description').text()\n", | |
" }\n", | |
" html += '<tr><td>{author}</td><td><a href=\"{url}\" target=\"_blank\">{description}</a></td></tr>'.format( **t ) \n", | |
"\n", | |
"html = '<table><tr><th>User</th><th>description</th></tr>' + html + '</table>'\n", | |
"HTML( html )" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"with open( 'index.html','w') as f:\n", | |
" f.write( html )" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"ename": "NameError", | |
"evalue": "name 'git' is not defined", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-10-3af29937df2a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mrepo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgit\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mRepo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'.'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mindex\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'forked_gists.ipynb'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhtml\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mindex\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcommit\u001b[0m\u001b[0;34m(\u001b[0m \u001b[0mmessage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"Committed from the notebook\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mrepo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremotes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'origin'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpush\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mNameError\u001b[0m: name 'git' is not defined" | |
] | |
} | |
], | |
"source": [ | |
"repo = git.Repo('.')\n", | |
"index = repo.index\n", | |
"index.add(['forked_gists.ipynb', index.html])\n", | |
"index.commit( message = \"Committed from the notebook\")\n", | |
"repo.remotes['origin'].push()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"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.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table><tr><th>User</th><th>description</th></tr><tr><td> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment