# Path: lib/utilities.py
# def url_to_json(url, headers={}):
#     """Returns the JSON response from the url.
# 
#     Args:
#         url (string): URL from which to GET the JSON resource.
# 
#     Returns:
#         dict: JSON of the response or empty dict on error.
#     """
#     request = urllib.request.Request(
#         url,
#         headers=headers
#     )
# 
#     try:
#         response = urllib.request.urlopen(request)
# 
#         raw_data = response.readall().decode('utf-8')
#         result = json.loads(raw_data)
#     except Exception as e:
#         # TODO: Properly handle error. For now, just return empty dictionary.
#         result = {}
# 
#     return result


import apscheduler.schedulers.background
import datetime
import queue
import sys
from lib.utilities import url_to_json
                'authentication.'
            )

        for token in tokens:
            self.available_tokens.put(token)

    def tokenize(self, url):
        if url.startswith('https://api.github.com'):
            if self.have_tokens:
                token = self.get_token()
                if token is not None:
                    return '{0}?access_token={1}'.format(url, token)
                else:
                    return url
            else:
                return url
        else:
            raise ValueError('url must be for the GitHub API')

    def get_token(self):
        while True:
            if not self.scheduler.get_jobs() and self.available_tokens.empty():
                self.print_warning('No more valid OAuth tokens available.')
                return None

            token = self.available_tokens.get(block=True)

            rate_limit_url = (
                'https://api.github.com/rate_limit?access_token={0}'
            ).format(token)

# Path: lib/utilities.py
# def url_to_json(url, headers={}):
#     """Returns the JSON response from the url.
# 
#     Args:
#         url (string): URL from which to GET the JSON resource.
# 
#     Returns:
#         dict: JSON of the response or empty dict on error.
#     """
#     request = urllib.request.Request(
#         url,
#         headers=headers
#     )
# 
#     try:
#         response = urllib.request.urlopen(request)
# 
#         raw_data = response.readall().decode('utf-8')
#         result = json.loads(raw_data)
#     except Exception as e:
#         # TODO: Properly handle error. For now, just return empty dictionary.
#         result = {}
# 
#     return result


# Path: lib/core.py
import apscheduler.schedulers.background
import datetime
import queue
import sys
from lib.utilities import url_to_json

                'authentication.'
            )

        for token in tokens:
            self.available_tokens.put(token)

    def tokenize(self, url):
        if url.startswith('https://api.github.com'):
            if self.have_tokens:
                token = self.get_token()
                if token is not None:
                    return '{0}?access_token={1}'.format(url, token)
                else:
                    return url
            else:
                return url
        else:
            raise ValueError('url must be for the GitHub API')

    def get_token(self):
        while True:
            if not self.scheduler.get_jobs() and self.available_tokens.empty():
                self.print_warning('No more valid OAuth tokens available.')
                return None

            token = self.available_tokens.get(block=True)

            rate_limit_url = (
                'https://api.github.com/rate_limit?access_token={0}'
            ).format(token)

            status = url_to_json(rate_limit_url)