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

Start work on supporting images

parent 3bb12ded
Branches
No related tags found
No related merge requests found
Pipeline #76059 passed
......@@ -20,6 +20,7 @@ from string import Template
import asyncio
import aiohttp
import requests
import hashlib
import feedparser
......@@ -116,9 +117,31 @@ class RSSBot(Plugin):
**entry._asdict(),
}), 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]:
# Download image from url feed.thumbnail.url
data = requests.get(feed.thumbnail.url, stream = True)
if data.status_code == 200:
data.raw_decode = True
try:
# Upload image to homeserver
mxc = self.client.upload_media(
data, mime_type=feed.thumbnail.mime_type, size=feed.thumbnail.size)
# Send image
# TODO: Maybe set additional metadata
# TODO: Set filename
await self.client.send_image(sub.room_id, mxc)
except MatrixResponseError:
pass
async def _send_with_image(self, feed: Feed, entry: Entry, sub: Subscription) -> Awaitable[EventID]:
await self._send(feed, entry, sub)
if feed.thumbnail:
await self._send_image(feed, entry, sub)
async def _broadcast(self, feed: Feed, entry: Entry, subscriptions: List[Subscription]) -> None:
spam_sleep = self.config["spam_sleep"]
tasks = [self._send(feed, entry, sub) for sub in subscriptions]
tasks = [self._send_with_image(feed, entry, sub) for sub in subscriptions]
for task in tasks:
try:
await task
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment