我正在尝试在给定Github用户名的情况下访问每个存储库中使用的语言。为了做到这一点,到目前为止,我的python代码是:
from pygithub3 import Github
username = raw_input("Please enter a Github username: ")
password = raw_input("Please enter the account password: ")
gh = Github(login=username, password = password)
get_user = gh.users.get()
user_repos = gh.repos.list().all().language
print user_repos
但是,列表对象显然没有任何语言属性,所以我不知道如何访问该信息。有没有人有任何帮助?
答案 0 :(得分:2)
试试这个男人,它对我有用:
from pygithub3 import Github
username = raw_input("Please enter a Github username: ")
password = raw_input("Please enter the account password: ")
gh = Github(login=username, password = password)
get_user = gh.users.get()
user_repos = gh.repos.list().all()
for repo in user_repos:
print repo.language
答案 1 :(得分:0)
我设法访问了这些信息,并获得了每种类型的计数:
from pygithub3 import Github
#declare variables
python = 0
cplusplus = 0
javascript = 0
ruby = 0
java = 0
#user input
username = raw_input("Please enter your Github username: ")
password = raw_input("Please enter your account password: ")
user = raw_input("Please enter the requested Github username: ")
#Connect to github
gh = Github(login=username, password = password)
get_user = gh.users.get(user)
user_repos = gh.repos.list(user = user).all()
#Count language in each repo
for repo in user_repos:
if repo.language == "Python":
python = python + 1
elif repo.language == "JavaScript":
javascript = javascript + 1
elif repo.language == "Ruby":
ruby = ruby + 1
elif repo.language == "C++":
cplusplus = cplusplus + 1
elif repo.language == "Java":
java = java + 1
#Print results
print "Number of Python repositories: " + str(python)
print "Number of Javascript repositories: " + str(javascript)
print "Number of Ruby repositories: " + str(ruby)
print "Number of C++ repositories: " + str(cplusplus)
print "Number of Java repositories: " + str(java)