-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathget_user_repositories.py
55 lines (50 loc) · 1.68 KB
/
get_user_repositories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import base64
import github
import sys
import os
# make a directory to save the Python files
if not os.path.exists("python-files"):
os.mkdir("python-files")
def print_repo(repo):
# repository full name
print("Full name:", repo.full_name)
# repository description
print("Description:", repo.description)
# the date of when the repo was created
print("Date created:", repo.created_at)
# the date of the last git push
print("Date of last push:", repo.pushed_at)
# home website (if available)
print("Home Page:", repo.homepage)
# programming language
print("Language:", repo.language)
# number of forks
print("Number of forks:", repo.forks)
# number of stars
print("Number of stars:", repo.stargazers_count)
print("-"*50)
# repository content (files & directories)
print("Contents:")
try:
for content in repo.get_contents(""):
# check if it's a Python file
if content.path.endswith(".py"):
# save the file
filename = os.path.join("python-files", f"{repo.full_name.replace('/', '-')}-{content.path}")
with open(filename, "wb") as f:
f.write(content.decoded_content)
print(content)
# repo license
print("License:", base64.b64decode(repo.get_license().content.encode()).decode())
except Exception as e:
print("Error:", e)
# Github username from the command line
username = sys.argv[1]
# pygithub object
g = github.Github()
# get that user by username
user = g.get_user(username)
# iterate over all public repositories
for repo in user.get_repos():
print_repo(repo)
print("="*100)