File tree 2 files changed +24
-10
lines changed
2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 1
1
import base64
2
- from github import Github
2
+ import github
3
3
import sys
4
+ import os
5
+
6
+ # make a directory to save the Python files
7
+ if not os .path .exists ("python-files" ):
8
+ os .mkdir ("python-files" )
4
9
5
10
6
11
def print_repo (repo ):
@@ -23,19 +28,25 @@ def print_repo(repo):
23
28
print ("-" * 50 )
24
29
# repository content (files & directories)
25
30
print ("Contents:" )
26
- for content in repo .get_contents ("" ):
27
- print (content )
28
31
try :
32
+ for content in repo .get_contents ("" ):
33
+ # check if it's a Python file
34
+ if content .path .endswith (".py" ):
35
+ # save the file
36
+ filename = os .path .join ("python-files" , f"{ repo .full_name .replace ('/' , '-' )} -{ content .path } " )
37
+ with open (filename , "wb" ) as f :
38
+ f .write (content .decoded_content )
39
+ print (content )
29
40
# repo license
30
41
print ("License:" , base64 .b64decode (repo .get_license ().content .encode ()).decode ())
31
- except :
32
- pass
42
+ except Exception as e :
43
+ print ( "Error:" , e )
33
44
34
45
35
46
# Github username from the command line
36
47
username = sys .argv [1 ]
37
48
# pygithub object
38
- g = Github ()
49
+ g = github . Github ()
39
50
# get that user by username
40
51
user = g .get_user (username )
41
52
# iterate over all public repositories
Original file line number Diff line number Diff line change 1
- from github import Github
1
+ import github
2
2
import base64
3
3
4
4
def print_repo (repo ):
@@ -21,8 +21,11 @@ def print_repo(repo):
21
21
print ("-" * 50 )
22
22
# repository content (files & directories)
23
23
print ("Contents:" )
24
- for content in repo .get_contents ("" ):
25
- print (content )
24
+ try :
25
+ for content in repo .get_contents ("" ):
26
+ print (content )
27
+ except github .GithubException as e :
28
+ print ("Error:" , e )
26
29
try :
27
30
# repo license
28
31
print ("License:" , base64 .b64decode (repo .get_license ().content .encode ()).decode ())
@@ -33,7 +36,7 @@ def print_repo(repo):
33
36
username = "username"
34
37
password = "password"
35
38
# initialize github object
36
- g = Github (username , password )
39
+ g = github . Github (username , password )
37
40
# or use public version
38
41
# g = Github()
39
42
You can’t perform that action at this time.
0 commit comments