Last active
August 8, 2016 19:12
-
-
Save oesteban/0247d772713e0a051b67ada16668b1b0 to your computer and use it in GitHub Desktop.
an API-created gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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