File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change 11import base64
2- from github import Github
2+ import github
33import 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" )
49
510
611def print_repo (repo ):
@@ -23,19 +28,25 @@ def print_repo(repo):
2328 print ("-" * 50 )
2429 # repository content (files & directories)
2530 print ("Contents:" )
26- for content in repo .get_contents ("" ):
27- print (content )
2831 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 )
2940 # repo license
3041 print ("License:" , base64 .b64decode (repo .get_license ().content .encode ()).decode ())
31- except :
32- pass
42+ except Exception as e :
43+ print ( "Error:" , e )
3344
3445
3546# Github username from the command line
3647username = sys .argv [1 ]
3748# pygithub object
38- g = Github ()
49+ g = github . Github ()
3950# get that user by username
4051user = g .get_user (username )
4152# iterate over all public repositories
Original file line number Diff line number Diff line change 1- from github import Github
1+ import github
22import base64
33
44def print_repo (repo ):
@@ -21,8 +21,11 @@ def print_repo(repo):
2121 print ("-" * 50 )
2222 # repository content (files & directories)
2323 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 )
2629 try :
2730 # repo license
2831 print ("License:" , base64 .b64decode (repo .get_license ().content .encode ()).decode ())
@@ -33,7 +36,7 @@ def print_repo(repo):
3336username = "username"
3437password = "password"
3538# initialize github object
36- g = Github (username , password )
39+ g = github . Github (username , password )
3740# or use public version
3841# g = Github()
3942
You can’t perform that action at this time.
0 commit comments