#NEWLINE# def get( self ) : #NEWLINE# #INDENT# headers = { #NEWLINE# #INDENT# 'User-Agent' : 'Openflock' , #NEWLINE# #UNINDENT# } #NEWLINE# url_queries = self . request . GET #NEWLINE# state = url_queries [ 'state' ] #NEWLINE# code = url_queries [ 'code' ] #NEWLINE# url = ( ( ( ( ( ( ( 'https://github.com/login/oauth/access_token?client_id=' + client__id ) + '&client_secret=' ) + client__secret ) + '&redirect_uri=' ) + redirect__uri ) + '&scope=&code=' ) + str ( code ) ) #NEWLINE# req = requests . post ( url , headers = headers ) #NEWLINE# req = str ( req . content ) #NEWLINE# access_token = '' #NEWLINE# i = 13 #NEWLINE# while ( req [ i ] != '&' ) : #NEWLINE# #INDENT# access_token = ( access_token + req [ i ] ) #NEWLINE# i = ( i + 1 ) #NEWLINE# #UNINDENT# user_api_url = ( 'https://api.github.com/user?access_token=' + str ( access_token ) ) #NEWLINE# user_json_data = requests . get ( user_api_url , headers = headers ) #NEWLINE# d = json . loads ( user_json_data . content ) #NEWLINE# username = d [ 'login' ] #NEWLINE# self . response . out . write ( ( str ( access_token ) + user_api_url ) ) #NEWLINE# if d [ 'name' ] : #NEWLINE# #INDENT# fullname = d [ 'name' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fullname = str ( username ) #NEWLINE# #UNINDENT# self . session [ 'username' ] = username #NEWLINE# avatar_url = d [ 'avatar_url' ] #NEWLINE# user_html_url = d [ 'html_url' ] #NEWLINE# if d [ 'blog' ] : #NEWLINE# #INDENT# website = d [ 'blog' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# website = '' #NEWLINE# #UNINDENT# if d [ 'email' ] : #NEWLINE# #INDENT# email = d [ 'email' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# email = '' #NEWLINE# #UNINDENT# if d [ 'location' ] : #NEWLINE# #INDENT# location = d [ 'location' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# location = '' #NEWLINE# #UNINDENT# public_repos = d [ 'public_repos' ] #NEWLINE# followers = d [ 'followers' ] #NEWLINE# following = d [ 'following' ] #NEWLINE# repos_url = d [ 'repos_url' ] #NEWLINE# repos_url = ( ( repos_url + '?access_token=' ) + access_token ) #NEWLINE# lang = [ ] #NEWLINE# res = requests . get ( repos_url , headers = headers ) #NEWLINE# response_code = res . status_code #NEWLINE# if ( response_code != 200 ) : #NEWLINE# #INDENT# self . response . out . write ( ( ( ( str ( response_code ) + ' ' ) + str ( res . headers ) ) + " Something's wrong with GitHub API!" ) ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( response_code == 200 ) : #NEWLINE# #INDENT# cont = res . json ( ) #NEWLINE# for item in cont : #NEWLINE# #INDENT# if ( ( item [ 'fork' ] == False ) and ( item [ 'private' ] == False ) ) : #NEWLINE# #INDENT# reponame = item [ 'name' ] #NEWLINE# repo_html_url = item [ 'html_url' ] #NEWLINE# username = item [ 'owner' ] [ 'login' ] #NEWLINE# if item [ 'language' ] : #NEWLINE# #INDENT# language = item [ 'language' ] #NEWLINE# lang . append ( language ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# language = 'none' #NEWLINE# #UNINDENT# forks = item [ 'forks' ] #NEWLINE# stars = item [ 'stargazers_count' ] #NEWLINE# homepage = item [ 'homepage' ] #NEWLINE# description = item [ 'description' ] #NEWLINE# repo_instance = RepoData ( key_name = reponame , reponame = reponame , repo_html_url = repo_html_url , username = username , language = language , forks = str ( forks ) , stars = str ( stars ) , website = homepage , description = description ) #NEWLINE# repo_instance . put ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# lang_list = list ( set ( lang ) ) #NEWLINE# if ( None in lang_list ) : #NEWLINE# #INDENT# lang_list . remove ( None ) #NEWLINE# #UNINDENT# orgs_url = ( ( ( 'https://api.github.com/users/' + str ( username ) ) + '/orgs?access_token=' ) + str ( access_token ) ) #NEWLINE# orgs = [ ] #NEWLINE# org_details = requests . get ( orgs_url , headers = headers ) #NEWLINE# response_code = org_details . status_code #NEWLINE# if ( response_code != 200 ) : #NEWLINE# #INDENT# self . response . out . write ( ( str ( response_code ) + " Something's wrong...Moslty with interaction of Openflock with GitHub API!" ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( response_code == 200 ) : #NEWLINE# #INDENT# result = org_details . json ( ) #NEWLINE# for org in result : #NEWLINE# #INDENT# org_username = org [ 'login' ] #NEWLINE# orgs . append ( org_username ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# user_instance = UserData ( key_name = username , fullname = fullname , username = username , orgs = orgs , access_token = str ( access_token ) , email = email , location = location , website = website , lang_list = lang_list , public_repos = str ( public_repos ) , followers = str ( followers ) , following = str ( following ) , avatar_url = avatar_url ) #NEWLINE# user_instance . put ( ) #NEWLINE# self . redirect ( '/' )