#NEWLINE# def get_auth_token( ) : #NEWLINE# #INDENT# global token #NEWLINE# if ( token is not None ) : #NEWLINE# #INDENT# return token #NEWLINE# #UNINDENT# import keyring #NEWLINE# token = keyring . get_password ( 'github' , fake_username ) #NEWLINE# if ( token is not None ) : #NEWLINE# #INDENT# return token #NEWLINE# #UNINDENT# print ( 'Please enter your github username and password. These are not stored, only used to get an oAuth token. You can revoke this at any time on Github.' ) #NEWLINE# user = input ( 'Username: ' ) #NEWLINE# pw = getpass . getpass ( 'Password: ' ) #NEWLINE# auth_request = { #NEWLINE# #INDENT# 'scopes' : [ 'public_repo' , 'gist' ] , #NEWLINE# 'note' : 'IPython tools' , #NEWLINE# 'note_url' : 'https://github.com/ipython/ipython/tree/master/tools' , #NEWLINE# #UNINDENT# } #NEWLINE# response = requests . post ( 'https://api.github.com/authorizations' , auth = ( user , pw ) , data = json . dumps ( auth_request ) ) #NEWLINE# response . raise_for_status ( ) #NEWLINE# token = json . loads ( response . text ) [ 'token' ] #NEWLINE# keyring . set_password ( 'github' , fake_username , token ) #NEWLINE# return token