-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: introducing dependency injector and switched from aiohttp t…
…o httpx client
- Loading branch information
Showing
20 changed files
with
543 additions
and
220 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from dependency_injector.wiring import Provide, inject | ||
|
||
from mightstone.ass import stream_as_list | ||
from mightstone.containers import Container | ||
from mightstone.services.scryfall import Scryfall | ||
|
||
|
||
@inject | ||
def main( | ||
scry: Scryfall = Provide[Container.scryfall], | ||
) -> None: | ||
found = stream_as_list(scry.search("boseiju")) | ||
|
||
print(f"Found {len(found)} instances of Boseiju") | ||
for card in found: | ||
print(f" - {card}") | ||
|
||
|
||
if __name__ == "__main__": | ||
container = Container() | ||
container.init_resources() | ||
container.wire(modules=[__name__]) | ||
|
||
main() |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,33 +1,42 @@ | ||
import httpx_cache | ||
import logging.config | ||
from appdirs import user_cache_dir | ||
from dependency_injector import containers, providers | ||
|
||
from .config import Settings | ||
from .services.cardconjurer import CardConjurer | ||
from .services.edhrec import EdhRecApi, EdhRecStatic | ||
from .services.mtgjson import MtgJson | ||
from .services.scryfall import Scryfall | ||
|
||
|
||
class Container(containers.DeclarativeContainer): | ||
config = providers.Configuration(pydantic_settings=[Settings()]) | ||
logging = providers.Resource( | ||
logging.config.dictConfig, | ||
fname="logging.ini", | ||
) | ||
|
||
# Gateways | ||
httpx_client = providers.Singleton( | ||
httpx_cache.AsyncClient, | ||
config.database.dsn, | ||
httpx_cache_transport = providers.Factory( | ||
httpx_cache.AsyncCacheControlTransport, | ||
cache=httpx_cache.FileCache(cache_dir=user_cache_dir("mightstone")), | ||
) | ||
|
||
# s3_client = providers.Singleton( | ||
# boto3.client, | ||
# service_name="s3", | ||
# aws_access_key_id=config.aws.access_key_id, | ||
# aws_secret_access_key=config.aws.secret_access_key, | ||
# ) | ||
|
||
# Services | ||
scryfall = providers.Factory( | ||
Scryfall, | ||
client=httpx_client, | ||
transport=httpx_cache_transport, | ||
) | ||
|
||
edhrec_static = providers.Factory( | ||
EdhRecStatic, | ||
transport=httpx_cache_transport, | ||
) | ||
|
||
edhrec_api = providers.Factory( | ||
EdhRecApi, | ||
transport=httpx_cache_transport, | ||
) | ||
|
||
card_conjurer = providers.Factory( | ||
CardConjurer, | ||
transport=httpx_cache_transport, | ||
) | ||
|
||
mtg_json = providers.Factory( | ||
MtgJson, | ||
transport=httpx_cache_transport, | ||
) |
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
Oops, something went wrong.