Skip to content

Commit 8f3ae81

Browse files
committed
sphinx: Add example script to create gists.
Thanks to Jane Wang for the script.
1 parent ecff461 commit 8f3ae81

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

doc/sphinx/source/configuration.rst

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,47 @@ behalf. If set, this overrides `pastebin_url`. It also overrides `pastebin_show_
7171
as the helper is expected to return the full URL to the pastebin as the first word of
7272
its output. The data is supplied to the helper via STDIN.
7373

74-
An example helper program is ``pastebinit``, available for most systems.
74+
An example helper program is ``pastebinit``, available for most systems. The
75+
following helper program can be used to create `gists <http://gist.github.com>`_:
76+
77+
.. code-block:: python
78+
79+
#!/usr/bin/env python
80+
81+
import sys
82+
import urllib2
83+
import json
84+
85+
def do_gist_json(s):
86+
""" Use json to post to github. """
87+
gist_public = False
88+
gist_url = 'https://api.github.com/gists'
89+
90+
data = {'description': None,
91+
'public': None,
92+
'files' : {
93+
'sample': { 'content': None }
94+
}}
95+
data['description'] = 'Gist from BPython'
96+
data['public'] = gist_public
97+
data['files']['sample']['content'] = s
98+
99+
req = urllib2.Request(gist_url, json.dumps(data), {'Content-Type': 'application/json'})
100+
try:
101+
res = urllib2.urlopen(req)
102+
except HTTPError, e:
103+
return e
104+
105+
try:
106+
json_res = json.loads(res.read())
107+
return json_res['html_url']
108+
except HTTPError, e:
109+
return e
110+
111+
if __name__ == "__main__":
112+
s = sys.stdin.read()
113+
print do_gist_json(s)
114+
75115
76116
.. versionadded:: 0.12
77117

0 commit comments

Comments
 (0)