Functions¶
src.utils.scryfall.scryfall_request_wrapper(logr: Any = None) -> Callable
¶
Wrapper for a Scryfall request function to handle retries, rate limits, and a final exception catch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logr
|
Any
|
Logger object to output any exception messages. |
None
|
Returns:
| Type | Description |
|---|---|
Callable
|
Wrapped function. |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_error(error: ScryfallError, response: Optional[requests.Response] = None, **kwargs) -> ScryfallException
¶
Returns a ScryfallException object created using data from a ScryfallError object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
ScryfallError
|
ScryfallError object returned from a failed Scryfall API request. |
required |
response
|
Response | None
|
A requests Response object containing details of the failed Scryfall request, if not provided defaults to a None value. |
None
|
Returns:
| Type | Description |
|---|---|
ScryfallException
|
A ScryfallException object. |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_card_unique(card_set: str, card_number: str, lang: str = 'en') -> Union[dict, ScryfallException]
¶
Get card using /cards/:code/:number(/:lang) Scryfall API endpoint.
Notes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_set
|
str
|
Set code of the card, ex: MH2 |
required |
card_number
|
str
|
Collector number of the card |
required |
lang
|
str
|
Lang code to look for, ex: en |
'en'
|
Returns:
| Type | Description |
|---|---|
dict | ScryfallException
|
Card dict or ScryfallException |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_card_search(card_name: str, card_set: Optional[str] = None, lang: str = 'en', **kwargs) -> Union[dict, ScryfallException]
¶
Get card using /cards/search Scryfall API endpoint.
Notes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_name
|
str
|
Name of the card, ex: Damnation |
required |
card_set
|
str | None
|
Set code to look for, ex: MH2 |
None
|
lang
|
str
|
Lang code to look for, ex: en |
'en'
|
Returns:
| Type | Description |
|---|---|
dict | ScryfallException
|
Card dict or ScryfallException |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_cards_paged(url: Union[yarl.URL, ScryURL, None] = None, all_pages: bool = True, **kwargs) -> list[dict]
¶
Grab paginated card list from a Scryfall API endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL | ScryURL | None
|
Scryfall API URL endpoint to access, uses Scryfall Search API if not provided. |
None
|
all_pages
|
bool
|
Whether to return all additional pages, or just the first. Returns all by default. |
True
|
**kwargs
|
Optional parameters to pass to API endpoint. |
{}
|
Source code in src\utils\scryfall.py
src.utils.scryfall.get_cards_oracle(oracle_id: str, all_pages: bool = False, **kwargs) -> list[dict]
¶
Grab paginated card list from a Scryfall API endpoint using the Oracle ID of the card.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oracle_id
|
str
|
Scryfall Oracle ID of the card. |
required |
all_pages
|
bool
|
Whether to return all additional pages, or just the first. |
False
|
**kwargs
|
Optional parameters to pass to API endpoint. |
{}
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of card objects. |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_set(card_set: str) -> dict
¶
Grab Set data from Scryfall.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_set
|
str
|
The set to look for, ex: MH2 |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Scryfall set dict or empty dict. |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_uri_object(url: yarl.URL, **kwargs) -> dict
¶
Pull a single object from Scryfall using a URI from a previous Scryfall data set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL
|
Formatted URL to pull object from. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A Scryfall object, e.g. Card, Set, etc. |
Source code in src\utils\scryfall.py
src.utils.scryfall.get_card_scan(img_url: str) -> Path
¶
Downloads scryfall art from URL
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_url
|
str
|
Scryfall URI for image. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Filename of the saved image, None if unsuccessful. |
Raises:
| Type | Description |
|---|---|
RequestException
|
If image couldn't be retrieved. |
Source code in src\utils\scryfall.py
src.utils.scryfall.is_playable_card(card_json: dict) -> bool
¶
Checks if this card object is a playable game piece.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
card_json
|
dict
|
Scryfall data for this card. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Valid scryfall data if check passed, else None. |