33
44# MIT License
55#
6- # Copyright (c) 2021 Tahmid Rayat
6+ # Copyright (c) 2022 Tahmid Rayat
77#
88# Permission is hereby granted, free of charge, to any person obtaining a copy
99# of this software and associated documentation files (the "Software"), to deal
2323# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424# SOFTWARE.
2525#
26- # Copyright (C) 2021 HTR-TECH (https://github.com/htr-tech)
26+ # Copyright (C) 2022 HTR-TECH (https://github.com/htr-tech)
2727#
2828
2929import os
3030import sys
3131import json
32+ import csv
3233import six
3334import requests
3435
5758"""
5859
5960def status (user ):
60- main = requests .get ("https://api.github.com/users/%s" % ( user ) )
61+ main = requests .get (f "https://api.github.com/users/{ user } " )
6162 if main .status_code == 200 :
6263 pass
6364 elif main .status_code == 404 :
6465 print ('No Github Account with that Username !' )
6566 sys .exit ()
6667 else :
67- print ('Try again After Some Time' )
68+ print ('Github api issue. Try again After Some Time' )
6869 sys .exit ()
6970
7071def stats (user ):
7172 status (user )
72- main = requests .get ("https://api.github.com/users/%s" % ( user ) )
73+ main = requests .get (f "https://api.github.com/users/{ user } " )
7374 dump = json .loads (main .text )
7475
7576 h1 = dump ['login' ]
@@ -91,30 +92,39 @@ def stats(user):
9192 print (info % (h1 , h2 , h3 , h4 , h5 , h6 , h7 , h8 ,
9293 h9 , h10 , h11 , h12 , h13 , h14 , h1 , h1 , h15 ))
9394
94- orgs = requests .get ("https://api.github.com/users/%s /orgs" % ( user ) )
95+ orgs = requests .get (f "https://api.github.com/users/{ user } /orgs" )
9596 orgs_dump = json .loads (orgs .text )
9697 for hulu in orgs_dump :
9798 print ('[-] Organization : {} ' .format (hulu ['login' ]))
9899
99- list_repo = six .moves .input (
100- '\n [-] Wanna List repositories [Max 100] [Y/n] : ' )
101- print ('' )
100+ stats = []
101+ total_star , total_fork = 0 , 0
102+
103+ if h11 > 100 : page_c = (h11 // 100 ) + 1
104+ else : page_c = 1
102105
103- if list_repo == "y" or list_repo == "Y" :
104- repos = requests .get (
105- "https://api.github.com/users/%s/repos?per_page=100" % (user ))
106+ for i in range (page_c ):
107+ repos = requests .get (f"https://api.github.com/users/{ user } /repos?page={ i + 1 } &per_page=100" )
106108 repo_dump = json .loads (repos .text )
107- for bagh in repo_dump :
108- print ('[-] Repo Name :: {} \n [-] Stars :: {} \n [-] Forks :: {} \n [-] Clone URL :: {}\n ' .format (
109- bagh ['name' ], bagh ['stargazers_count' ], bagh ['forks_count' ], bagh ['clone_url' ]))
109+ for x in repo_dump :
110+ stats .append ((x ['name' ],x ['stargazers_count' ],x ['forks_count' ],x ['clone_url' ]))
111+ total_star += int (x ['stargazers_count' ])
112+ total_fork += int (x ['forks_count' ])
113+
114+ print ('' )
115+ print ('[-] Total Stars : ' + str (total_star ))
116+ print ('[-] Total Forks : ' + str (total_fork ))
117+ print ('' )
110118
111- total_star , total_fork = 0 , 0
112- for bagh in repo_dump :
113- total_star += int (bagh ['stargazers_count' ])
114- total_fork += int (bagh ['forks_count' ])
119+ save_repo = six .moves .input ('[-] Save Repository List as .csv ? [Y/n] : ' )
120+ print ('' )
115121
116- print ('[-] Total Stars : ' + str (total_star ))
117- print ('[-] Total Forks : ' + str (total_fork ))
122+ if save_repo == "y" or save_repo == "Y" :
123+ with open (f'{ user } .csv' ,'w' , newline = '' , encoding = 'utf-8' ) as f :
124+ output = csv .writer (f )
125+ output .writerow (['Repository Name' ,'Total Stars' ,'Total Forks' ,'Clone URL' ])
126+ for w in stats : output .writerow (w )
127+ print (f'[-] File Saved as : { user } .csv' )
118128 print ('' )
119129 else :
120130 pass
0 commit comments