project-stats

keep track of your projects
git clone https://git.ce9e.org/project-stats.git

commit
cc9bdcc243d87f43028c1ef16c72baf672637cbd
parent
8a6839e7fa38bd96ac18312a2941574c9ad99439
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-03-22 14:39
more robust github get_json

Diffstat

M projects.py 16 +++++++++++-----

1 files changed, 11 insertions, 5 deletions


diff --git a/projects.py b/projects.py

@@ -168,9 +168,11 @@ def get_xml(url):
  168   168 
  169   169 
  170   170 def get_github(url, user=None, password=None):
  171    -1     api_url = re.sub(
  172    -1         'https?://github.com', 'https://api.github.com/repos', url)
  173    -1     data = get_json(api_url, user=user, password=password)
   -1   171     def _get_json(url):
   -1   172         data = get_json(url, user=user, password=password)
   -1   173         if 'documentation_url' in data:
   -1   174             raise requests.RequestError(data['documentation_url'])
   -1   175         return data
  174   176 
  175   177     def get_all_pages(url):
  176   178         l = []
@@ -178,11 +180,15 @@ def get_github(url, user=None, password=None):
  178   180         page = 1
  179   181         while new:
  180   182             u = url + '?page=%i' % page
  181    -1             new = get_json(u, user=user, password=password)
   -1   183             new = _get_json(u)
  182   184             l += new
  183   185             page += 1
  184   186         return l
  185   187 
   -1   188     api_url = re.sub(
   -1   189         'https?://github.com', 'https://api.github.com/repos', url)
   -1   190     data = _get_json(api_url)
   -1   191 
  186   192     def get_latest_tag():
  187   193         tags = get_all_pages(data['tags_url'])
  188   194         tags = map(lambda tag: tag['name'], tags)
@@ -191,7 +197,7 @@ def get_github(url, user=None, password=None):
  191   197 
  192   198     def get_open_pull_requests():
  193   199         url = data['pulls_url'].replace('{/number}', '')
  194    -1         pulls = get_json(url)
   -1   200         pulls = _get_json(url)
  195   201         return len(pulls)
  196   202 
  197   203     return {