Esempio n. 1
0
import uplink

# Local imports
from github import BASE_URL, GitHub


@defer.inlineCallbacks
def get_contributors(full_name):
    print('Getting GitHub repository `{}`'.format(full_name))
    response = yield gh_async.get_contributors(*full_name.split("/"))
    json = response.json()
    print('response for {}: {}'.format(full_name, json))


if __name__ == "__main__":
    # This consumer instance uses Requests to make blocking requests.
    gh_sync = GitHub(base_url=BASE_URL)

    # This uses Twisted with Requests, inspired by `requests-threads`.
    gh_async = GitHub(base_url=BASE_URL, client=uplink.TwistedClient())

    # First, let's fetch a list of all public repositories.
    repos = gh_sync.get_repos().json()

    # Use only the first 10 results to avoid hitting the rate limit.
    repos = repos[:10]

    # Asynchronously fetch the contributors for those 10 repositories.
    deferred = [get_contributors(repo["full_name"]) for repo in repos]
    reactor.callLater(2, reactor.stop)  # Stop the reactor after 2 secs
    reactor.run()
Esempio n. 2
0
        sys.exit(1)

    result = []
    if len(sys.argv) == 2:
        args = re.sub('\s+', ' ', sys.argv[1]).split(' ')
        cache = Cache(CACHE_FILE)
        github = GitHub(github_api_key)

        if args[0] == '!refresh':
            refresh_cache(cache, github)
            print generate_placeholder_xml("Finished cached refreshing")
            sys.exit(0)

        if len(args) >= 2:
            owner, repo_name = args[:2]
            repos = cache.get(owner) or github.get_repos(owner)
            result = {
                repo: (owner + ' ' + repo, get_repo_url(owner, repo))
                for repo in repos
                if is_match(repo_name, repo) or repo_name == ''
            }

            if repos and not cache.has_key(owner):
                cache.put(owner, repos)
                cache.save()
        else:
            result = guess_repo(cache, args[0])
            result.update(suggest_owner(cache, args[0]))

    if result:
        print generate_xml(result)