Created
November 10, 2012 15:08
-
-
Save mmurdoch/4051357 to your computer and use it in GitHub Desktop.
Example of using github library for Pythonista.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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