Skip to content

Instantly share code, notes, and snippets.

@oesteban
Last active August 8, 2016 19:12
Show Gist options
  • Save oesteban/0247d772713e0a051b67ada16668b1b0 to your computer and use it in GitHub Desktop.
Save oesteban/0247d772713e0a051b67ada16668b1b0 to your computer and use it in GitHub Desktop.
an API-created gist
#!/opt/conda/bin/python
"""
Convert files to json objects uploadable to GitHub gists using:
curl -v -H "Authorization: token <insert token here>" -X POST https://api.github.com/gists --data @<filename.json>
"""
import sys
import json
import os.path as op
fname = op.basename(sys.argv[1])
with open(sys.argv[1], 'r') as myfile:
fcontents=''.join(myfile.readlines())
jsdict = {
'description': 'an API-created gist',
'public': True,
'files': {
'{}'.format(fname): {
'content': fcontents
}
}
}
with open(sys.argv[2], 'w') as outfile:
json.dump(jsdict, outfile, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment