project-stats

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

commit
09f6a06dbfa7eeac5354e9c0281b39e1033cc557
parent
eeeb3ab77e11ab13f6dc0c8e33d57f231a32a098
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2017-07-23 20:56
use github token instead of password

Diffstat

M project_stats.py 17 +++++++++--------

1 files changed, 9 insertions, 8 deletions


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

@@ -162,24 +162,25 @@ def cheesecake_index(name):
  162   162         return None
  163   163 
  164   164 
  165    -1 async def get_json(url, user=None, password=None):
  166    -1     assert not (user is None) ^ (password is None)
   -1   165 async def get_json(url, user=None, token=None):
   -1   166     assert not (user is None) ^ (token is None)
  167   167 
  168    -1     auth = None
  169   168     if user is not None:
  170    -1         auth=aiohttp.BasicAuth(user, password)
   -1   169         # FIXME: not very robust
   -1   170         url += '&' if '?' in url else '?'
   -1   171         url += 'login=%s&token=%s' % (user, token)
  171   172 
  172    -1     async with aiohttp.ClientSession(auth=auth) as session:
   -1   173     async with aiohttp.ClientSession() as session:
  173   174         async with session.get(url) as resp:
  174   175             return await resp.json()
  175   176 
  176   177 
  177    -1 async def get_github(url, user=None, password=None):
   -1   178 async def get_github(url, user=None, token=None):
  178   179     api_url = re.sub(
  179   180         'https?://github.com', 'https://api.github.com/repos', url)
  180   181 
  181   182     async def _get_json(url):
  182    -1         data = await get_json(url, user=user, password=password)
   -1   183         data = await get_json(url, user=user, token=token)
  183   184         if 'documentation_url' in data:
  184   185             raise aiohttp.ClientError(data['documentation_url'])
  185   186         return data
@@ -338,7 +339,7 @@ async def get_source(key, source, config, claims):
  338   339         future = fn(
  339   340             source,
  340   341             user=r_get(config, 'github', 'user'),
  341    -1             password=r_get(config, 'github', 'password'))
   -1   342             token=r_get(config, 'github', 'token'))
  342   343     elif key == 'gitlab':
  343   344         future = fn(source, token=r_get(config, 'gitlab', 'token'))
  344   345     else: