Skip to content

Instantly share code, notes, and snippets.

@raylu
Created April 19, 2013 00:58
Show Gist options
  • Save raylu/5417390 to your computer and use it in GitHub Desktop.
Save raylu/5417390 to your computer and use it in GitHub Desktop.
gist paster
#!/usr/bin/env python
import requests
import sys
rs = requests.Session()
if len(sys.argv) == 2:
filename = sys.argv[1]
f = open(filename, 'r')
r = rs.get('https://gist.github.com/languages/detect', params={'name': filename})
language = r.json()['language']
else:
filename = 'file'
f = sys.stdin
language = 'Text'
content = f.read()
data = {
'gist[description]': '',
'gist[files][][content]': content,
'gist[files][][language]': language,
'gist[files][][name]': filename,
'gist[public]': 0,
'indent': 'Tabs',
}
r = rs.post('https://gist.github.com/gists', data=data, allow_redirects=False)
print r.headers['location']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment