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?

Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51

2 Answers2

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
Sharif Mamun
  • 3,508
  • 5
  • 32
  • 51
  • 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#)? – jacksterooney Feb 28 '14 at 10:08
  • Disregard that, I figured it out using the code below: – jacksterooney Feb 28 '14 at 11:55
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)