Skip to content
Snippets Groups Projects
Unverified Commit f082cd0d authored by Srdjan Grubor's avatar Srdjan Grubor Committed by GitHub
Browse files

Merge pull request #16 from endlessm/fixes-for-upstream

Fixes for upstream
parents 51f20050 cbbcebc8
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
# encoding: utf-8
import base64
import sys
import os
import argparse
from collections import namedtuple
from subprocess import Popen, PIPE
from urllib2 import urlopen
from urllib import urlencode
from urllib2 import Request, urlopen
import json
from urlparse import urlparse
......@@ -15,14 +17,14 @@ WHITELIST=[]
BLACKLIST=[]
LISTINGS_PER_PAGE = 100
ACCESS_TOKEN_PARAM = '?access_token=%s'
LISTING_PAGE_PARAM = '&per_page=%d&page=%d'
LISTINGS_PER_PAGE_PARAM = 'per_page'
LISTING_PAGE_PARAM = 'page'
GITHUB_API_HOST = 'https://api.github.com'
GIT_CLONE_CMD = 'git clone %s %s %s'
GIT_CLONE_API_URL = 'https://%s@github.com/%s'
GIT_SHA_CMD = 'git rev-parse --short %s'
GIT_FETCH_CMD = 'git fetch'
GIT_FETCH_CMD = 'git fetch --tags'
GIT_CHECK_REMOTE_CMD = 'git ls-remote'
USER_DETAILS_PATH = '/users/%s'
......@@ -73,12 +75,23 @@ class AttributeDict(dict):
self[attr] = value
def read_api_uri(uri, config, page=1):
uri += ACCESS_TOKEN_PARAM % config.token + LISTING_PAGE_PARAM % (LISTINGS_PER_PAGE, page)
params = {
LISTINGS_PER_PAGE_PARAM: LISTINGS_PER_PAGE,
LISTING_PAGE_PARAM: page,
}
uri += '?' + urlencode(params)
creds = base64.b64encode(config.token.encode('utf-8')).decode('ascii')
basic_auth = 'Basic {}'.format(creds)
headers = {
'Authorization': basic_auth,
}
if config.debug:
print "Trying:", uri
print "Trying URI {} with headers {}".format(uri, headers)
return urlopen(uri).read()
req = Request(uri, headers=headers)
return urlopen(req).read()
def get_json(uri, config, obj_type=AttributeDict, page=1):
return json.loads(read_api_uri(uri, config, page), object_hook=obj_type)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment