Created
August 25, 2011 17:42
-
-
Save grodtron/1171258 to your computer and use it in GitHub Desktop.
A gist to test the Gist API
This file contains 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
#!/usr/bin/python | |
import urllib2 | |
import base64 | |
import json | |
filename = __file__.split("/")[-1] | |
data = {} | |
data["description"] = "A gist to test the Gist API" | |
data["public"] = True | |
data["files"] = {filename:{}} | |
data["files"][filename]["content"] = open(__file__).read().replace("******", "******") | |
url = "https://api.github.com/gists" | |
auth_string = "grodtron:******" | |
auth_string = base64.encodestring(auth_string)[:-1] | |
req = urllib2.Request(url, json.dumps(data)) | |
req.add_header("Authorization", "Basic %s" % auth_string) | |
try: | |
result = urllib2.urlopen(req) | |
print result.read() | |
except urllib2.URLError, e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment