Gist Code Examples
Examples withGist
s
Listing gists after authenticating
fromgithub3importlogingh=login(username,password)gists=[gforgingh.iter_gists()]
Creating a gist after authenticating
fromgithub3importlogingh=login(username,password)files={'spam.txt':{'content':'What... is the air-speed velocity of an unladen swallow?'}}gist=gh.create_gist('Answer this to cross the bridge',files,public=False)# gist == <Gist [gist-id]>print(gist.html_url)
Creating an anonymous gist
fromgithub3importcreate_gistfiles={'spam.txt':{'content':'What... is the air-speed velocity of an unladen swallow?'}}gist=create_gist('Answer this to cross the bridge',files)comments=[cforcingist.iter_comments()]# []comment=gist.create_comment('Bogus. This will not work.')# Which of course it didn't, because you're not logged in# comment == Noneprint(gist.html_url)
In the above examples'spam.txt'
is the file name. GitHub will autodetectfile type based on extension provided.'What…istheair-speedvelocityofanunladenswallow?'
is the file’s content or body.'Answerthistocrossthebridge'
is the gist’s description. While required by github3.py, it isallowed to be empty, e.g.,''
is accepted by GitHub.
Note that anonymous gists are always public.