From 3813267ea7c1f554bbeebe4cac43bdfd0e60dee9 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 23 Mar 2011 08:30:14 -0400 Subject: [PATCH] docstrings --- humble/core.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/humble/core.py b/humble/core.py index 9712991..54ac5f6 100644 --- a/humble/core.py +++ b/humble/core.py @@ -1,17 +1,52 @@ # -*- coding: utf-8 -*- +""" +humble.cli +~~~~~~~~~~ + +This module contains the main API interface for Humble. + +""" + + +import json + from github2.client import Github +import requests github = Github() +__title__ = 'humble' +__version__ = '0.1.0' +__build__ = 0x000100 +__author__ = 'Kenneth Reitz' +__license__ = 'ISC' +__copyright__ = 'Copyright 2011 Kenneth Reitz' +__docformat__ = 'restructuredtext' + + +GITHUB_API = 'http://github.com/api/v1/json/' + + + def get_info_for(username): - return github.users.show(username) + try: + return github.users.show(username) + except RuntimeError: + return None def get_repos_for(username): - return github.repos.list(username) + + r = requests.get('{0}{1}'.format(GITHUB_API, username)) + repos = json.loads(r.content).get('user', {}).get('repositories', None) + + def _sort(repo): + return repo.get('watchers', '0') + + return sorted(repos, key=_sort, reverse=True) # print get_repos_for('kennethreitz')