Skip to content

Commit 15a114c

Browse files
authored
GithubStat 1.1
2 parents f49c8c2 + 5c3db17 commit 15a114c

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

GithubStat/__init__.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
@@ -23,12 +23,13 @@
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

2929
import os
3030
import sys
3131
import json
32+
import csv
3233
import six
3334
import requests
3435

@@ -57,19 +58,19 @@
5758
"""
5859

5960
def 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

7071
def 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

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Tahmid Rayat
3+
Copyright (c) 2022 Tahmid Rayat
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $ python setup.py install
3838
$ GithubStat <github-username>
3939
```
4040

41-
***Copyright (c) 2021 Tahmid Rayat Under [MIT LICENSE](https://github.com/htr-tech/GithubStat/blob/master/LICENSE#L1)***
41+
***Copyright (c) 2022 Tahmid Rayat Under [MIT LICENSE](https://github.com/htr-tech/GithubStat/blob/master/LICENSE#L1)***
4242

4343
### *📡 Get in Touch :*
4444
[![Github](https://img.shields.io/badge/Github-525252?style=for-the-badge&logo=github)](https://github.com/htr-tech)

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name = "GithubStat",
9-
version = "1.0",
9+
version = "1.1",
1010
license = "MIT",
1111
author = "HTR-TECH",
1212
author_email = "tahmidrayat@gmail.com",
@@ -26,6 +26,8 @@
2626
'Programming Language :: Python :: 3.7',
2727
'Programming Language :: Python :: 3.8',
2828
'Programming Language :: Python :: 3.9',
29+
'Programming Language :: Python :: 3.10',
30+
'Programming Language :: Python :: 3.11',
2931
],
3032
packages = find_packages(),
3133
zip_safe = True,

0 commit comments

Comments
 (0)