Last active
August 29, 2015 14:00
-
-
Save kparms/02600e6f17da0b0dcf1e to your computer and use it in GitHub Desktop.
Gist Api Fun
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
import http.client | |
import json | |
def gist_get(): | |
conn = http.client.HTTPSConnection("api.github.com") | |
headers = { | |
'Content-type' : 'application/json', | |
'User-Agent' : 'Does this really have to be anything' | |
} | |
emptyparams = { } | |
conn.request("GET", "/gists/public", emptyparams, headers) | |
#conn.request("GET", "/users/kparms/gists", emptyparams, headers) | |
response = conn.getresponse() | |
response = response.read().decode() | |
#print (type(response)) | |
d = json.loads(response) | |
#print (len(d)) | |
#print (d) | |
for item in d: | |
print (item['html_url']) | |
print (item['owner']['login']) | |
response = gist_get() | |
#print (response) |
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
import http.client | |
import json | |
def gist_write(name, content): | |
conn = http.client.HTTPSConnection("api.github.com") | |
headers = { | |
'Content-type' : 'application/json', | |
'User-Agent' : 'Does this really have to be anything' | |
} | |
params = { | |
'description': name, | |
'public': True, | |
'files': { | |
'file1.txt': { | |
'content': content | |
} | |
} | |
} | |
json_params = json.dumps(params) | |
conn.request("POST", "/gists", json_params, headers) | |
response = conn.getresponse() | |
print (response.read().decode()) | |
response = gist_write("testgist", "Here is a gist that I made") | |
print (response) |
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
I created a new document and added it to this git repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment