Getting repository information using pygithub3 for Python

后端 未结 2 1311
感动是毒
感动是毒 2021-01-29 03:57

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

         


        
相关标签:
2条回答
  • 2021-01-29 04:34

    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)
    
    0 讨论(0)
  • 2021-01-29 04:40

    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
    
    0 讨论(0)
提交回复
热议问题