Skip to content

Instantly share code, notes, and snippets.

@mmurdoch
Created November 10, 2012 15:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmurdoch/4051357 to your computer and use it in GitHub Desktop.
Save mmurdoch/4051357 to your computer and use it in GitHub Desktop.
Example of using github library for Pythonista.
import console
import keychain
import traceback
from github import Github
def printRepository(username):
g = Github(username, getGithubPassword(username))
user = g.get_user()
repositories = user.get_repos()
for repository in repositories:
print repository.name
printBranches(repository)
def printBranches(repository):
for branch in repository.get_branches():
print ' ', branch.name
tree = branch.commit.commit.tree
printTree(repository, tree, ' ')
def printTree(repository, tree, indent):
for element in tree.tree:
print indent, element.path
if element.type == 'tree':
printTree(repository, repository.get_git_tree(element.sha), indent + ' ')
def getGithubPassword(username):
service = 'github'
password = keychain.get_password(service, username)
if password == None:
print "Enter password for user", username
password = console.secure_input()
keychain.set_password(service, username, password)
return password
# Pass your Github username as a parameter
printRepository('your_github_username')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment