Skip to content

Commit

Permalink
fix #136
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Apr 14, 2024
1 parent aba4b84 commit d6584a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions film2trello/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,20 @@ 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(
process_inbox(
board_id,
trello_key=trello_key,
trello_token=trello_token,
sort_cards=sort_cards,
)
)
except HTTPStatusError as exc:
Expand Down
12 changes: 8 additions & 4 deletions film2trello/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
13 changes: 7 additions & 6 deletions film2trello/trello.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit d6584a6

Please sign in to comment.