You've already forked wakapi-readme-stats
fix: status code 202 error
This commit is contained in:
@@ -21,7 +21,8 @@ async def create_loc_graph(yearly_data: Dict, save_path: str):
|
|||||||
:param save_path: Path to save the graph file.
|
:param save_path: Path to save the graph file.
|
||||||
"""
|
"""
|
||||||
colors = await DM.get_remote_yaml("linguist")
|
colors = await DM.get_remote_yaml("linguist")
|
||||||
|
if colors is None:
|
||||||
|
colors = dict()
|
||||||
years = len(yearly_data.keys())
|
years = len(yearly_data.keys())
|
||||||
year_indexes = arange(years)
|
year_indexes = arange(years)
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ async def get_waka_time_stats(repositories: Dict, commit_dates: Dict) -> str:
|
|||||||
stats = str()
|
stats = str()
|
||||||
|
|
||||||
data = await DM.get_remote_json("waka_latest")
|
data = await DM.get_remote_json("waka_latest")
|
||||||
|
if data is None:
|
||||||
|
DBM.p("WakaTime data unavailable!")
|
||||||
|
return stats
|
||||||
if EM.SHOW_COMMIT or EM.SHOW_DAYS_OF_WEEK: # if any on flag is turned on then we need to calculate the data and print accordingly
|
if EM.SHOW_COMMIT or EM.SHOW_DAYS_OF_WEEK: # if any on flag is turned on then we need to calculate the data and print accordingly
|
||||||
DBM.i("Adding user commit day time info...")
|
DBM.i("Adding user commit day time info...")
|
||||||
stats += f"{await make_commit_day_time_list(data['data']['timezone'], repositories, commit_dates)}\n\n"
|
stats += f"{await make_commit_day_time_list(data['data']['timezone'], repositories, commit_dates)}\n\n"
|
||||||
@@ -89,6 +92,9 @@ async def get_short_github_info() -> str:
|
|||||||
stats += f"> 📦 {disk_usage} \n > \n"
|
stats += f"> 📦 {disk_usage} \n > \n"
|
||||||
|
|
||||||
data = await DM.get_remote_json("github_stats")
|
data = await DM.get_remote_json("github_stats")
|
||||||
|
if data is None:
|
||||||
|
DBM.p("GitHub contributions data unavailable!")
|
||||||
|
return stats
|
||||||
DBM.i("Adding contributions info...")
|
DBM.i("Adding contributions info...")
|
||||||
if len(data["years"]) > 0:
|
if len(data["years"]) > 0:
|
||||||
contributions = FM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
|
contributions = FM.t("Contributions in the year") % (intcomma(data["years"][0]["total"]), data["years"][0]["year"])
|
||||||
@@ -161,6 +167,9 @@ async def get_stats() -> str:
|
|||||||
if EM.SHOW_TOTAL_CODE_TIME:
|
if EM.SHOW_TOTAL_CODE_TIME:
|
||||||
DBM.i("Adding total code time info...")
|
DBM.i("Adding total code time info...")
|
||||||
data = await DM.get_remote_json("waka_all")
|
data = await DM.get_remote_json("waka_all")
|
||||||
|
if data is None:
|
||||||
|
DBM.p("WakaTime data unavailable!")
|
||||||
|
else:
|
||||||
stats += f"}-{quote(str(data['data']['text']))}-blue)\n\n"
|
stats += f"}-{quote(str(data['data']['text']))}-blue)\n\n"
|
||||||
|
|
||||||
if EM.SHOW_PROFILE_VIEWS:
|
if EM.SHOW_PROFILE_VIEWS:
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class DownloadManager:
|
|||||||
await resource
|
await resource
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def _get_remote_resource(resource: str, convertor: Optional[Callable[[bytes], Dict]]) -> Dict:
|
async def _get_remote_resource(resource: str, convertor: Optional[Callable[[bytes], Dict]]) -> Dict or None:
|
||||||
"""
|
"""
|
||||||
Receive execution result of static query, wait for it if necessary.
|
Receive execution result of static query, wait for it if necessary.
|
||||||
If the query wasn't cached previously, cache it.
|
If the query wasn't cached previously, cache it.
|
||||||
@@ -174,7 +174,7 @@ class DownloadManager:
|
|||||||
:param resource: Static query identifier.
|
:param resource: Static query identifier.
|
||||||
:param convertor: Optional function to convert `response.contents` to dict.
|
:param convertor: Optional function to convert `response.contents` to dict.
|
||||||
By default `response.json()` is used.
|
By default `response.json()` is used.
|
||||||
:return: Response dictionary.
|
:return: Response dictionary or None.
|
||||||
"""
|
"""
|
||||||
DBM.i(f"\tMaking a remote API query named '{resource}'...")
|
DBM.i(f"\tMaking a remote API query named '{resource}'...")
|
||||||
if isinstance(DownloadManager._REMOTE_RESOURCES_CACHE[resource], Awaitable):
|
if isinstance(DownloadManager._REMOTE_RESOURCES_CACHE[resource], Awaitable):
|
||||||
@@ -184,16 +184,22 @@ class DownloadManager:
|
|||||||
else:
|
else:
|
||||||
res = DownloadManager._REMOTE_RESOURCES_CACHE[resource]
|
res = DownloadManager._REMOTE_RESOURCES_CACHE[resource]
|
||||||
DBM.g(f"\tQuery '{resource}' loaded from cache!")
|
DBM.g(f"\tQuery '{resource}' loaded from cache!")
|
||||||
if res.status_code == 200 or res.status_code == 202:
|
if res.status_code == 200:
|
||||||
if convertor is None:
|
if convertor is None:
|
||||||
return res.json()
|
return res.json()
|
||||||
else:
|
else:
|
||||||
return convertor(res.content)
|
return convertor(res.content)
|
||||||
|
elif res.status_code == 201:
|
||||||
|
DBM.w(f"\tQuery '{resource}' returned 201 status code")
|
||||||
|
return None
|
||||||
|
elif res.status_code == 202:
|
||||||
|
DBM.w(f"\tQuery '{resource}' returned 202 status code")
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Query '{res.url}' failed to run by returning code of {res.status_code}: {res.json()}")
|
raise Exception(f"Query '{res.url}' failed to run by returning code of {res.status_code}: {res.json()}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_remote_json(resource: str) -> Dict:
|
async def get_remote_json(resource: str) -> Dict or None:
|
||||||
"""
|
"""
|
||||||
Shortcut for `_get_remote_resource` to return JSON response data.
|
Shortcut for `_get_remote_resource` to return JSON response data.
|
||||||
:param resource: Static query identifier.
|
:param resource: Static query identifier.
|
||||||
@@ -202,7 +208,7 @@ class DownloadManager:
|
|||||||
return await DownloadManager._get_remote_resource(resource, None)
|
return await DownloadManager._get_remote_resource(resource, None)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_remote_yaml(resource: str) -> Dict:
|
async def get_remote_yaml(resource: str) -> Dict or None:
|
||||||
"""
|
"""
|
||||||
Shortcut for `_get_remote_resource` to return YAML response data.
|
Shortcut for `_get_remote_resource` to return YAML response data.
|
||||||
:param resource: Static query identifier.
|
:param resource: Static query identifier.
|
||||||
|
|||||||
Reference in New Issue
Block a user