Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Forked from anonymous/Untitled118.ipynb
Created April 12, 2017 02:48
Show Gist options
  • Select an option

  • Save tonyfast/2e6f839faefebd3b125e56113e22d59f to your computer and use it in GitHub Desktop.

Select an option

Save tonyfast/2e6f839faefebd3b125e56113e22d59f to your computer and use it in GitHub Desktop.
This experiment shares a notebook to an anonymous gist.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# coding: utf-8
# # `POST` an anonymous [gist](https://developer.github.com/v3/gists/)
# In[1]:
filename = 'Untitled118.ipynb'
# In[36]:
import ujson
import nbconvert
import nbformat
import os
import requests
from toolz.curried import *
# In[40]:
def _opener(input, filename=None):
dirname, _filename = os.path.split(input)
if filename and filename.startswith('.'):
filename = _filename.replace('.ipynb', filename)
filename = filename or _filename
with open(filename) as f:
ret = f.read()
return filename, {
'content': ret
}
# In[51]:
class Post(nbconvert.postprocessors.PostProcessorBase):
def postprocess(self, input):
nb = nbformat.read(input, 4)
md = nb['metadata']
resp = requests.post(
url="https://api.github.com/gists",
json={
'files': merge(
{
filename: {
"content": ujson.dumps(nb)
}
}, dict(
_opener(input, filename=filename)
for filename in 'artifacts' in md and md['artifacts'] or []
)
),
'description': 'description' in md and md['description'] or "",
'public': True,
}
)
self = get_ipython()
self.log.warning("""{}""".format(resp.json()['html_url']))
return resp
# self.log.warning("")
resp = Post().postprocess(filename)
# # Autoformatting and linting.
# In[92]:
try:
output = juxt(
local['yapf']['-i'],
local['flake8']
)('Untitled118.py')
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment