|
5 | 5 | import os |
6 | 6 | import pathlib |
7 | 7 | import re |
8 | | -import sys |
| 8 | +from datetime import datetime |
9 | 9 | from time import time |
10 | 10 | from typing import Any, Optional, Tuple |
11 | 11 |
|
@@ -130,18 +130,22 @@ def provide(self, subject: str) -> str: |
130 | 130 | headers=self._headers, |
131 | 131 | ) |
132 | 132 | if request.status == 200: |
133 | | - self._cache[subject] = json.loads( |
134 | | - request.data.decode('utf-8'))['title'] + ' (#%s)' % _id |
| 133 | + LOG.debug('github-api: \ue27d #%s', _id) |
| 134 | + json_data = json.loads(request.data.decode('utf-8')) |
| 135 | + self._cache[subject] = json_data['title'] + ' (#%s)' % _id |
135 | 136 | elif request.status == 401: |
136 | | - print('Failed to authenticate', file=sys.stderr) |
| 137 | + LOG.error('github-api: ⛔ authentication failure') |
137 | 138 | self.auth_failed = True |
138 | 139 | return subject |
139 | 140 | elif request.status == 403: |
140 | 141 | self._rate_limit = int( |
141 | 142 | request.headers['X-Ratelimit-Reset']) |
| 143 | + date = datetime.utcfromtimestamp(self._rate_limit) |
| 144 | + LOG.warning('github-api: ⚠ rate limited until %s', date) |
142 | 145 | return subject |
143 | 146 | else: |
144 | | - print(request.data, file=sys.stderr) |
| 147 | + LOG.error('github-api ⛔ (%s) %s', request.status, |
| 148 | + request.data) |
145 | 149 | return subject |
146 | 150 |
|
147 | 151 | return self._cache[subject] |
@@ -205,7 +209,7 @@ def provide(self, subject: str) -> str: |
205 | 209 | self._cache[subject] = json.loads( |
206 | 210 | request.data.decode('utf-8'))['title'] + ' (#%s)' % _id |
207 | 211 | elif request.status == 401: |
208 | | - print('Failed to authenticate', file=sys.stderr) |
| 212 | + LOG.error('Failed to authenticate') |
209 | 213 | self.auth_failed = True |
210 | 214 | return subject |
211 | 215 | else: |
|
0 commit comments