Getting repository information using pygithub3 for Python

一曲冷凌霜 提交于 2019-12-20 05:51:21

问题


I'm trying to access the language used in each repository given a Github username. In order to do this, so far my python code is:

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

However, the list object apparently doesn't have any language attribute, so I don't know how to access that information. Does anyone have any help?


回答1:


Try this man, it worked for me:

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



回答2:


I managed to access the information, and get a count of each type as well:

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)


来源:https://stackoverflow.com/questions/22083477/getting-repository-information-using-pygithub3-for-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!