This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from naveen521kk/api-v2
Support for API v2
- Loading branch information
Showing
17 changed files
with
335 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
utils.py | ||
~~~~~~~~ | ||
Extra utils used internally. | ||
""" | ||
__all__ = [] | ||
from .__logger__ import logger | ||
from .constants import SXCU_SUCCESS_CODE | ||
from .exceptions import SXCUError | ||
|
||
|
||
def join_url(subdomain: str, path: str) -> str: | ||
if path[0] != "/": | ||
path = "/" + path | ||
if subdomain[-1] != "/": | ||
return subdomain + path | ||
return subdomain[:-1] + path | ||
|
||
|
||
def raise_error(status_code: int, error_code: int, error: str) -> None: | ||
logger.error( | ||
"The status_code from remote is %s which was expected to be %s.", | ||
status_code, | ||
SXCU_SUCCESS_CODE, | ||
) | ||
logger.error("The error code is: %s ", error_code) | ||
logger.error("The reason for this error is: %s", error) | ||
raise SXCUError(error) | ||
|
||
|
||
def get_id_from_url(url: str) -> str: | ||
"""Get the id of the image from the url. | ||
The url is of the format https://sxcu.net/{image_id}, | ||
so we simply split the url by `/` and return the last part. | ||
Parameters | ||
---------- | ||
url : str | ||
The original url. | ||
Returns | ||
------- | ||
str | ||
The id of the image. | ||
""" | ||
sp = url.split("/") | ||
return sp[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.