Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 13365ab

Browse files
Merge pull request avinashkranjan#2029 from sabhisharma-ise/GitHub_Repos
added Python Script to View All GitHub Repos 👍
2 parents 849d761 + 627a7d8 commit 13365ab

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

‎All_GitHub_Repos/README.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# View All GitHub Repos
2+
3+
This script aims at providing access to the public repositories, given the username. Details of the repository such as name, date of creation, and so on are displayed. The library PyGithub, which is built on Python is used. The requests library is also used, in order to interact and obtain data from Github.
4+
5+
## Prerequisites
6+
7+
- Python 3.x
8+
9+
## Usage
10+
11+
1. Clone the repository or download the `all_github_repos.py` file.
12+
2. Open a terminal or command prompt and navigate to the directory where the file is located.
13+
3. Run the following command to start the program:
14+
15+
```shell
16+
python all_github_repos.py
17+
18+
## Output
19+
![Result](https://i.imgur.com/l38Zw5S.jpg)

‎All_GitHub_Repos/all_github_repos.py‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
3+
# to convert it into a script by running sudo chmod +x all_github_repos.py
4+
5+
import requests
6+
import sys
7+
from github import Github
8+
9+
# imports
10+
# pip3/pip install PyGithub is installed to work with the contents of the Github repositories
11+
12+
username = sys.argv[1]
13+
# reading the username as a commandline argument
14+
15+
url = f"https://api.github.com/users/{username}"
16+
17+
user_data = requests.get(url).json()
18+
# to retrieve data contained in the url in json format
19+
20+
21+
def repository_names(user):
22+
repo_names = []
23+
for repo in user.get_repos():
24+
repo_names.append(repo)
25+
return repo_names
26+
27+
28+
# fetching the names of all the repositories
29+
30+
31+
def repository_details(user):
32+
all_repo_details = []
33+
repo_names = repository_names(user)
34+
for repo in repo_names:
35+
repo_details = {}
36+
repo_details["Name"] = repo.full_name.split("/")[1]
37+
repo_details["Description"] = repo.description
38+
repo_details["Created on"] = repo.created_at
39+
repo_details["Programming language"] = repo.language
40+
repo_details["Forked"] = str(repo.forks) + " time(s)"
41+
all_repo_details.append(repo_details)
42+
return all_repo_details
43+
44+
45+
# fetching the details of all the repositories
46+
47+
48+
user = Github().get_user(username)
49+
50+
RD = repository_details(user)
51+
# fetching the details of all repositories
52+
# stored as a list of dictionaries
53+
54+
if __name__ == "__main__":
55+
for content in RD:
56+
# pprint.pprint(content)
57+
for title, description in content.items():
58+
print(title, ":", description)
59+
print(
60+
"\n-------------------------------------------------------------------------------------------------------------------\n"
61+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /