Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bluesky = "False"

[bluesky]
esa_handles = ["esa.int", "exploration.esa.int", "navigation.esa.int", "esaearth.esa.int", "science.esa.int", "transport.esa.int", "esaconnectivity.esa.int"]
space_handles = ["rocketlabcorp.com", "nasaspaceflight.com", "thalesaleniaspace.bsky.social", "eumetsat.int"]
space_handles = ["rocketlabcorp.com", "nasaspaceflight.com", "thalesaleniaspace.bsky.social", "eumetsat.int", "stsci.edu"]
6 changes: 5 additions & 1 deletion src/pimetheus/infrastructure/image/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ def compress_to_target(self, target_size_kb: int | None = None) -> Path:

logger.info("Processing image", path=self.filepath, size=original_size_kb, target_size=target_size_kb)

with Image.open(self.filepath) as img:
with Image.open(self.filepath) as img: # type: Image.Image
logger.info("Original dimensions", width=img.size[0], height=img.size[1], size=original_size_kb)

buffer = io.BytesIO()
quality = 100

if img.mode in ("RGBA", "P"):
img = img.convert("RGB")

img.thumbnail((self.MAX_DIMENSION, self.MAX_DIMENSION), Image.Resampling.LANCZOS)

while quality > 0:
Expand Down
7 changes: 5 additions & 2 deletions src/pimetheus/services/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pydantic import ValidationError

from pimetheus.infrastructure.http.exceptions import HTTPClientError
from pimetheus.infrastructure.image.exceptions import ImageProcessingError
from pimetheus.infrastructure.image.processor import ImageProcessor
from pimetheus.infrastructure.raspberrypi.system import GroundControl
from pimetheus.infrastructure.storage.files import FileStorage
Expand All @@ -33,8 +34,8 @@ class Bot:

settings = Settings.load()
MAX_IMAGE_SIZE_KB = 976
MIN_SLEEP_TIME = 3000
MAX_SLEEP_TIME = 3600
MIN_SLEEP_TIME = 3300
MAX_SLEEP_TIME = 3650

def __init__(self) -> None:
"""
Expand Down Expand Up @@ -204,6 +205,8 @@ def create_nasa_apod_message(self) -> None:
logger.error("Failed to fetch json", exc_info=e)
except NetworkError as e:
logger.error("Failed to publish post", exc_info=e)
except ImageProcessingError as e:
logger.error("Failed to process image", exc_info=e)
finally:
if fetcher is not None:
fetcher.http_client.close()
Expand Down
11 changes: 7 additions & 4 deletions src/pimetheus/services/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ def __init__(self, message_dict: dict[str, Any]) -> None:
logger.info("Starting Messenger")
self.message_dict = message_dict

self.twitter_client = TwitterAPIClient()
self.bluesky_client = BlueskyAPIClient()
self.bluesky_creator = BlueskyCreator(self.bluesky_client)

self.twitter = self.settings.pimetheus.twitter
self.bluesky = self.settings.pimetheus.bluesky

if self.twitter:
self.twitter_client = TwitterAPIClient()

if self.bluesky:
self.bluesky_client = BlueskyAPIClient()
self.bluesky_creator = BlueskyCreator(self.bluesky_client)

def create_twitter_message(self) -> str:
"""
Build formatted X post text.
Expand Down
Loading