mirror of
https://github.com/cquest/tootbot.git
synced 2025-03-29 08:56:44 +00:00
use links when available to embed images
This commit is contained in:
parent
b163d3e115
commit
6a58efdec9
@ -98,11 +98,20 @@ for t in reversed(d.entries):
|
|||||||
c = ("RT https://twitter.com/%s\n" % t.author[2:-1]) + c
|
c = ("RT https://twitter.com/%s\n" % t.author[2:-1]) + c
|
||||||
toot_media = []
|
toot_media = []
|
||||||
# get the pictures...
|
# get the pictures...
|
||||||
|
if 'summary' in t:
|
||||||
for p in re.finditer(r"https://pbs.twimg.com/[^ \xa0\"]*", t.summary):
|
for p in re.finditer(r"https://pbs.twimg.com/[^ \xa0\"]*", t.summary):
|
||||||
media = requests.get(p.group(0))
|
media = requests.get(p.group(0))
|
||||||
media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type'))
|
media_posted = mastodon_api.media_post(media.content, mime_type=media.headers.get('content-type'))
|
||||||
toot_media.append(media_posted['id'])
|
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
|
# replace short links by original URL
|
||||||
m = re.search(r"http[^ \xa0]*", c)
|
m = re.search(r"http[^ \xa0]*", c)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user