Skip to content

Instantly share code, notes, and snippets.

@kparms
Last active August 29, 2015 14:00
Show Gist options
  • Save kparms/02600e6f17da0b0dcf1e to your computer and use it in GitHub Desktop.
Save kparms/02600e6f17da0b0dcf1e to your computer and use it in GitHub Desktop.
Gist Api Fun
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)
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)
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