forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_github_repositories.py
57 lines (52 loc) · 1.53 KB
/
search_github_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
56
57
import github
import base64
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(""):
print(content)
except github.GithubException as e:
print("Error:", e)
try:
# repo license
print("License:", base64.b64decode(repo.get_license().content.encode()).decode())
except:
pass
# your github account credentials
username = "username"
password = "password"
# initialize github object
g = github.Github(username, password)
# or use public version
# g = Github()
# search repositories by name
for repo in g.search_repositories("pythoncode tutorials"):
# print repository details
print_repo(repo)
print("="*100)
print("="*100)
print("="*100)
# search by programming language
for i, repo in enumerate(g.search_repositories("language:python")):
print_repo(repo)
print("="*100)
if i == 9:
break