0

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?

3
  • what do you get with "user_repos = gh.repos.list().all()" ? Commented Feb 28, 2014 at 0:11
  • Just the name of all the repos, in a list. Commented Feb 28, 2014 at 9:51
  • have you been able to do the same with ssh keys? Commented Jan 27, 2016 at 21:38

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

However, just to add to this question, the output is a whole bunch of strings one after the other - is there anyway either to convert the output to a single list, or to count the number of similar outputs (e.g. Python, C#)?
Disregard that, I figured it out using the code below:
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.