diff --git a/bluemastofeed.py b/bluemastofeed.py index f6b3d46..c18a69b 100644 --- a/bluemastofeed.py +++ b/bluemastofeed.py @@ -161,15 +161,19 @@ def fetch_og_data(url): return None, None -def post_to_bluesky(message, link): +def post_to_bluesky(title, link, tags): client = Client() client.login(BSKY_HANDLE, BSKY_PASSWORD) - title, image_url = fetch_og_data(link) - text = title or message + hashtags = " ".join(f"#{tag}" for tag in tags) if tags else "" + message = f"{title}\n\n{link}" + if hashtags: + message += f"\n\n{hashtags}" - if title and image_url: - try: + # Try rich embed + try: + og_title, image_url = fetch_og_data(link) + if og_title and image_url: embed = { "$type": "app.bsky.embed.external", "external": { @@ -190,13 +194,14 @@ def post_to_bluesky(message, link): blob = client.upload_blob(BytesIO(img_resp.content)) embed["external"]["thumb"] = blob.blob - client.send_post(text=text, embed=embed) + client.send_post(text=message, embed=embed) logger.info(f"✅ Posted to Bluesky with preview.") return - except Exception as e: - logger.error(f"❌ Error uploading preview to Bluesky: {e}") + except Exception as e: + logger.error(f"❌ Error uploading preview to Bluesky: {e}") - client.send_post(f"{text}\n{link}") + # Fallback to text-only post + client.send_post(text=message) logger.info(f"💡 Posted to Bluesky without preview.") @@ -265,7 +270,7 @@ def main(): time.sleep(2) if POST_TARGETS in ("bluesky", "both"): - post_to_bluesky(f"{title}\n{link}", link) + post_to_bluesky(title, link, tags) save_seen_id(post_id) logger.info(f"✅ Post successfully published.")