diff --git a/film2trello/cli.py b/film2trello/cli.py index 1ea61bf..1263bbd 100644 --- a/film2trello/cli.py +++ b/film2trello/cli.py @@ -91,10 +91,12 @@ def bot( @board_id_option @trello_key_option @trello_token_option +@click.option("--sort/--no-sort", "sort_cards", default=True) def inbox( board_id: str, trello_key: str, trello_token: str, + sort_cards: bool, ) -> None: try: asyncio.run( @@ -102,6 +104,7 @@ def inbox( board_id, trello_key=trello_key, trello_token=trello_token, + sort_cards=sort_cards, ) ) except HTTPStatusError as exc: diff --git a/film2trello/core.py b/film2trello/core.py index abc9f4a..9982ac3 100644 --- a/film2trello/core.py +++ b/film2trello/core.py @@ -152,6 +152,7 @@ async def process_inbox( scraper: httpx.AsyncClient, trello_api: httpx.AsyncClient, board_id: str, + sort_cards: bool = True, ) -> None: inbox_list_id, archive_list_id = await trello.get_working_lists_ids( trello_api, board_id @@ -197,10 +198,13 @@ async def process_inbox( else: logger.info("Card description doesn't contain CSFD.cz URL") - logger.info("Sorting cards") - for position, (card, _) in enumerate(sorted(index, key=sort_inbox_key), start=1): - logger.info(f"#{position}: {card['name']}") - await trello.update_card_position(trello_api, card["id"], position) + if sort_cards: + logger.info("Sorting cards") + for position, (card, _) in enumerate(sorted(index, key=sort_inbox_key), start=1): + logger.info(f"#{position}: {card['name']}") + await trello.update_card_position(trello_api, card["id"], position) + else: + logger.info("Skipping cards sorting") def sort_inbox_key(index_item: tuple[dict, Film]) -> tuple[int, int, str]: diff --git a/film2trello/trello.py b/film2trello/trello.py index 25637e2..9b0313c 100644 --- a/film2trello/trello.py +++ b/film2trello/trello.py @@ -288,9 +288,10 @@ def has_poster(attachments) -> bool: def create_thumbnail( image_bytes: bytes, ) -> tuple[Literal["poster.jpg"], BytesIO, Literal["image/jpeg"]]: - image = Image.open(image_bytes).convert("RGB") - image.thumbnail(THUMBNAIL_SIZE) - out_file = BytesIO() - image.save(out_file, "JPEG") - out_file.seek(0) - return ("poster.jpg", out_file, "image/jpeg") + with Image.open(BytesIO(image_bytes)) as image: + image = image.convert("RGB") + image.thumbnail(THUMBNAIL_SIZE) + out_file = BytesIO() + image.save(out_file, "JPEG") + out_file.seek(0) + return ("poster.jpg", out_file, "image/jpeg")