Skip to content
Snippets Groups Projects
Commit 4fc513a6 authored by Falk Rehse's avatar Falk Rehse
Browse files

Fix thumbnail logic

parent 64efbf49
No related branches found
No related tags found
No related merge requests found
...@@ -117,15 +117,15 @@ class RSSBot(Plugin): ...@@ -117,15 +117,15 @@ class RSSBot(Plugin):
**entry._asdict(), **entry._asdict(),
}), msgtype=MessageType.NOTICE if sub.send_notice else MessageType.TEXT, allow_html=True) }), msgtype=MessageType.NOTICE if sub.send_notice else MessageType.TEXT, allow_html=True)
async def _send_image(self, feed: Feed, entry: Entry, sub: Subscription) -> Awaitable[EventID]: async def _send_image(self, feed: Feed, entry: Entry, thumbnail: Thumbnail, sub: Subscription) -> Awaitable[EventID]:
# Download image from url feed.thumbnail.url # Download image from url thumbnail.url
data = requests.get(feed.thumbnail.url, stream = True) data = requests.get(thumbnail.url, stream = True)
if data.status_code == 200: if data.status_code == 200:
data.raw_decode = True data.raw_decode = True
try: try:
# Upload image to homeserver # Upload image to homeserver
mxc = self.client.upload_media( mxc = self.client.upload_media(
data, mime_type=feed.thumbnail.mime_type, size=feed.thumbnail.size) data, mime_type=thumbnail.mime_type, size=thumbnail.size)
# Send image # Send image
# TODO: Maybe set additional metadata # TODO: Maybe set additional metadata
...@@ -134,14 +134,15 @@ class RSSBot(Plugin): ...@@ -134,14 +134,15 @@ class RSSBot(Plugin):
except MatrixResponseError: except MatrixResponseError:
pass pass
async def _send_with_image(self, feed: Feed, entry: Entry, sub: Subscription) -> Awaitable[EventID]: async def _send_with_image(self, feed: Feed, entry: Entry, thumbnail: Thumbnail, sub: Subscription) -> Awaitable[EventID]:
await self._send(feed, entry, sub) await self._send(feed, entry, sub)
if feed.thumbnail: if thumbnail != None:
await self._send_image(feed, entry, sub) # TODO: Get thumbnail from db
await self._send_image(feed, entry, thumbnail, sub)
async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None: async def _broadcast(self, feed: Feed, entry: Entry, thumbnail: Thumbnail, subscriptions: List[Subscription]) -> None:
spam_sleep = self.config["spam_sleep"] spam_sleep = self.config["spam_sleep"]
tasks = [self._send_with_image(feed, entry, sub) for sub in subscriptions] tasks = [self._send_with_image(feed, entry, thumbnail, sub) for sub in subscriptions]
for task in tasks: for task in tasks:
try: try:
await task await task
...@@ -168,7 +169,7 @@ class RSSBot(Plugin): ...@@ -168,7 +169,7 @@ class RSSBot(Plugin):
new_entries.pop(old_entry.id, None) new_entries.pop(old_entry.id, None)
self.db.add_entries(new_entries.values()) self.db.add_entries(new_entries.values())
for entry in new_entries.values(): for entry in new_entries.values():
await self._broadcast(feed, entry, feed.subscriptions) await self._broadcast(feed, entry, feed.subscriptions) # TODO: Get thumbnail
async def _poll_feeds(self) -> None: async def _poll_feeds(self) -> None:
self.log.debug("Polling started") self.log.debug("Polling started")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment