mirror of
https://github.com/cquest/tootbot.git
synced 2025-01-18 12:26:58 +00:00
use links when available to embed images
This commit is contained in:
parent
b163d3e115
commit
6a58efdec9
17
tootbot.py
17
tootbot.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user