Skip to content

Commit

Permalink
feat: implement image attachment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sakuramochi0 committed Aug 15, 2024
1 parent ad5f6e0 commit 5aa9bfd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ atproto==0.0.41
feedparser==6.0.11
beautifulsoup4==4.12.3
python-dotenv==1.0.1
httpx==0.25.2
13 changes: 12 additions & 1 deletion rss2bsky.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import time

from atproto import Client, client_utils
from atproto_client import models
from bs4 import BeautifulSoup
from dotenv import load_dotenv
import httpx

load_dotenv()

Expand Down Expand Up @@ -85,9 +87,18 @@ def main():
if len(content.strip()) > 0:
rich_text = make_rich(content)
rich_text.link("Original post", item["link"])

images = []
if 'media_content' in item:
for media, media_text in zip(item['media_content'], item['content']):
img_data = httpx.get(media['url']).content
upload = client.upload_blob(img_data)
images.append(models.AppBskyEmbedImages.Image(alt=media_text['value'], image=upload.blob))
embed = models.AppBskyEmbedImages.Main(images=images)

if rss_time > last_bsky:
try:
client.send_post(rich_text)
client.send_post(text=rich_text, embed=embed)
logging.info("Sent post %s" % (item["link"]))
except Exception as e:
logging.exception("Failed to post %s" % (item["link"]))
Expand Down

0 comments on commit 5aa9bfd

Please sign in to comment.