fix(app): Add hashtags to bluesky post
This commit is contained in:
@ -161,15 +161,19 @@ def fetch_og_data(url):
|
|||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def post_to_bluesky(message, link):
|
def post_to_bluesky(title, link, tags):
|
||||||
client = Client()
|
client = Client()
|
||||||
client.login(BSKY_HANDLE, BSKY_PASSWORD)
|
client.login(BSKY_HANDLE, BSKY_PASSWORD)
|
||||||
|
|
||||||
title, image_url = fetch_og_data(link)
|
hashtags = " ".join(f"#{tag}" for tag in tags) if tags else ""
|
||||||
text = title or message
|
message = f"{title}\n\n{link}"
|
||||||
|
if hashtags:
|
||||||
|
message += f"\n\n{hashtags}"
|
||||||
|
|
||||||
if title and image_url:
|
# Try rich embed
|
||||||
try:
|
try:
|
||||||
|
og_title, image_url = fetch_og_data(link)
|
||||||
|
if og_title and image_url:
|
||||||
embed = {
|
embed = {
|
||||||
"$type": "app.bsky.embed.external",
|
"$type": "app.bsky.embed.external",
|
||||||
"external": {
|
"external": {
|
||||||
@ -190,13 +194,14 @@ def post_to_bluesky(message, link):
|
|||||||
blob = client.upload_blob(BytesIO(img_resp.content))
|
blob = client.upload_blob(BytesIO(img_resp.content))
|
||||||
embed["external"]["thumb"] = blob.blob
|
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.")
|
logger.info(f"✅ Posted to Bluesky with preview.")
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"❌ Error uploading preview to Bluesky: {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.")
|
logger.info(f"💡 Posted to Bluesky without preview.")
|
||||||
|
|
||||||
|
|
||||||
@ -265,7 +270,7 @@ def main():
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
if POST_TARGETS in ("bluesky", "both"):
|
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)
|
save_seen_id(post_id)
|
||||||
logger.info(f"✅ Post successfully published.")
|
logger.info(f"✅ Post successfully published.")
|
||||||
|
Reference in New Issue
Block a user