<commit_before>import github2.client
from django.conf import settings
import mysite.customs.ohloh
import simplejson
import mysite.base.helpers
import urllib
import urllib2

_github = None

# Always initialize this at module import time
# If this web app ran on an OLPC laptop, we'd be making
# children sad by running unnecessary code at module
# import time. But this seems just fine to me for a long-
# running server process.
_github = github2.client.Github(username=settings.GITHUB_USERNAME,
                               api_token=settings.GITHUB_API_TOKEN)

def _github_repos_list(username):
    return _github.repos.list(username)

def repos_by_username(username):
    try:
        repos = _github_repos_list(username)
    except urllib2.HTTPError, e:
        if e.code == 403:
            # Well, Github said 403
            # That seems to mean that there is no such Github user. So,
            # return the empty list.
            return
        else:
            raise # otherwise, wtf
    for repo in repos:
        yield repo

def find_primary_language_of_repo(github_username, github_reponame):
    # FIXME: Make this handle a few situations
    # * Repo does not exist (or rather, raise ValueError then)<commit_msg>And now we handle that case.<commit_after>import github2.client
from django.conf import settings
import mysite.customs.ohloh
import simplejson
import mysite.base.helpers
import urllib
import urllib2

_github = None

# Always initialize this at module import time
# If this web app ran on an OLPC laptop, we'd be making
# children sad by running unnecessary code at module
# import time. But this seems just fine to me for a long-
# running server process.
_github = github2.client.Github(username=settings.GITHUB_USERNAME,
                               api_token=settings.GITHUB_API_TOKEN)

def _github_repos_list(username):
    return _github.repos.list(username)

def repos_by_username(username):
    try:
        repos = _github_repos_list(username)
    except urllib2.HTTPError, e:
        if e.code == 403:
            # Well, Github said 403
            # That seems to mean that there is no such Github user. So,
            # return the empty list.
            return
        else:
            raise # otherwise, wtf
    except RuntimeError, re:
        if re.message == 'unexpected response from github.com 403: \'{"error":[{"error":"api route not recognized"}]}\'':
            return
    for repo in repos:
        yield repo

def find_primary_language_of_repo(github_username, github_reponame):
    # FIXME: Make this handle a few situations
    # * Repo does not exist (or rather, raise ValueError then)
{'fraction_non_alphanumeric': 0.0660626651566629, 'fraction_numerical': 0.008682521706304265, 'mean_word_length': 2.90279823269514, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866893', 'n_tokens_mistral': 780, 'n_tokens_neox': 747, 'n_words': 275}