Example #1
0
def fetch_and_render(id=None):
    """Fetch and render a post from the Github API"""
    if id is None:
        return redirect('/')

    r = requests.get('https://api.github.com/gists/{}'.format(id))

    if r.status_code != 200:
        abort(404)
    try:
        decoded = r.json.copy()
        files = decoded['files'].values()
        if len(files) == 1:
            jsonipynb = files[0]['content']
            converter = nbconvert.ConverterHTML()
            converter.nb = nbformat.reads_json(jsonipynb)
            result = converter.convert()
        else:
            entries = []
            for file in files:
                entry = {}
                entry['path'] = file['filename']
                entry['url'] = '/%s/%s' % (id, file['filename'])
                entries.append(entry)
            return render_template('gistlist.html', entries=entries)
    except ValueError as e:
        abort(404)

    return result
Example #2
0
def render_url(url):
    try:
        r = requests.get('http://'+url)

        if r.status_code != 200:
            return None

        converter = nbconvert.ConverterHTML()
        converter.nb = nbformat.reads_json(r.content)
        result = converter.convert()
        return result
    except ValueError :
        abort(501)
Example #3
0
def render_urls(url):
    try:
        r = requests.get('https://'+url)

        if r.status_code != 200:
            return None
        print 'will init converter'
        converter = nbconvert.ConverterHTML()
        print 'will set json'
        converter.nb = nbformat.reads_json(r.content)
        print 'will convert'
        result = converter.convert()
        print 'will return'
        return result
    except ValueError :
        abort(501)
Example #4
0
def fetch_and_render(id):
    """Fetch and render a post from the Github API"""
    r = requests.get('https://api.github.com/gists/{}'.format(id))

    if r.status_code != 200:
        return None
    try :
        decoded = r.json.copy()
        jsonipynb = decoded['files'].values()[0]['content']

        converter = nbconvert.ConverterHTML()
        converter.nb = nbformat.reads_json(jsonipynb)
        result = converter.convert()
    except ValueError as e :
        abort(404)

    return result
Example #5
0
def render_content(content):
    converter = nbconvert.ConverterHTML()
    converter.nb = nbformat.reads_json(content)
    return converter.convert()