get pics from nitter and fallback to twitter

This commit is contained in:
cquest 2022-12-14 13:44:16 +01:00
parent d54ca76d7e
commit b2185b6434

View File

@ -218,12 +218,22 @@ else:
if 'photos' in t: if 'photos' in t:
for url in t['photos']: for url in t['photos']:
print('photo', url) print('photo', url)
media = requests.get(url) try:
print("received") media = requests.get(url.replace(
'https://pbs.twimg.com/', 'https://nitter.net/pic/orig/'))
print("received nitter", media.headers.get('content-type'))
media_posted = mastodon_api.media_post( media_posted = mastodon_api.media_post(
media.content, mime_type=media.headers.get('content-type')) media.content, mime_type=media.headers.get('content-type'))
print("posted") print("posted")
toot_media.append(media_posted['id']) toot_media.append(media_posted['id'])
except:
media = requests.get(url)
print("received twitter", media.headers.get('content-type'))
media_posted = mastodon_api.media_post(
media.content, mime_type=media.headers.get('content-type'))
print("posted")
toot_media.append(media_posted['id'])
# replace short links by original URL # replace short links by original URL
links = re.findall(r"http[^ \xa0]*", c) links = re.findall(r"http[^ \xa0]*", c)