use links when available to embed images

This commit is contained in:
cquest 2022-05-02 16:06:17 +02:00
parent b163d3e115
commit 6a58efdec9

View File

@ -98,10 +98,19 @@ for t in reversed(d.entries):
c = ("RT https://twitter.com/%s\n" % t.author[2:-1]) + c
toot_media = []
# get the pictures...
for p in re.finditer(r"https://pbs.twimg.com/[^ \xa0\"]*", t.summary):
media = requests.get(p.group(0))
media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type'))
toot_media.append(media_posted['id'])
if 'summary' in t:
for p in re.finditer(r"https://pbs.twimg.com/[^ \xa0\"]*", t.summary):
media = requests.get(p.group(0))
media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type'))
toot_media.append(media_posted['id'])
if 'links' in t:
for l in t.links:
if l.type in ('image/jpg', 'image/png'):
media = requests.get(l.url)
media_posted = mastodon_api.media_post(
media.content, mime_type=media.headers.get('content-type'))
toot_media.append(media_posted['id'])
# replace short links by original URL
m = re.search(r"http[^ \xa0]*", c)