Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Take input from stdin and create a new public gist with it
#!/usr/bin/env python
import getpass, mechanize, optparse, os.path, sys
parser = optparse.OptionParser()
parser.add_option('--private', action='store_true', default=False)
(options, args) = parser.parse_args()
br = mechanize.Browser()
if options.login:
if not options.password:
options.password = getpass.getpass('Password for %s@github: ' % options.login)'')
br.form.find_control('login').value = options.login
br.form.find_control('password').value = options.password
result = br.submit()'')
br.form.find_control('file_contents[gistfile1]').value =
if options.filename:
br.form.find_control('file_name[gistfile1]').value = options.filename
if options.description:
br.form.find_control('description').value = options.description
if options.private:
print br.geturl()
if os.path.exists('/usr/bin/pbcopy'):
retval = os.system('echo %r | /usr/bin/pbcopy' % br.geturl())
if retval == 0:
print 'Copied gist url (%s) to the clipboard.' % br.geturl()

maraca commented Mar 15, 2011

Hi Marc,

I've taken the liberty to add buildout to your code to make it accesible to more people without having to install mechanize.
I've also added an option for syntax highlight when uploading.
You can find the code here:

Thanks a lot for your very useful snippet !

dejl commented Mar 3, 2013

MacBookPro:bin daniel$ gist
Traceback (most recent call last):
File "./gist", line 25, in'')
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize/", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize/", line 255, in _mech_open
raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt

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