Added tolerance for MastodonIllegalArgumentError when visiting linked page to extract picture

This commit is contained in:
JC Francois 2019-09-07 13:08:17 +02:00
parent 1ec03c7d81
commit 806b57f763

View File

@ -27,7 +27,7 @@ from bs4 import BeautifulSoup, element
import sqlite3 import sqlite3
import time import time
import re import re
from mastodon import Mastodon, MastodonError, MastodonAPIError from mastodon import Mastodon, MastodonError, MastodonAPIError, MastodonIllegalArgumentError
USER_AGENTS = [ USER_AGENTS = [
@ -208,10 +208,10 @@ def main(argv):
for p in photo_conts: for p in photo_conts:
photos.append(p['data-image-url']) photos.append(p['data-image-url'])
# Mention presence in videos in tweet # Mention presence of videos in tweet
videos = amoc.find_all('div', class_='AdaptiveMedia-videoContainer') videos = amoc.find_all('div', class_='AdaptiveMedia-videoContainer')
if len(videos) != 0: if len(videos) != 0:
tweet_text += '\n\n[Embedded video in original tweet]' tweet_text += '\n\n[Video embedded in original tweet]'
# If no media was specifically added in the tweet, try to get the first picture # If no media was specifically added in the tweet, try to get the first picture
# with "twitter:image" meta tag in first linked page in tweet text # with "twitter:image" meta tag in first linked page in tweet text
@ -320,6 +320,8 @@ def main(argv):
media_ids.append(media_posted['id']) media_ids.append(media_posted['id'])
except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.) except MastodonAPIError: # Media cannot be uploaded (invalid format, dead link, etc.)
pass pass
except MastodonIllegalArgumentError: # Could not determine mime type of content
pass
# Post toot # Post toot
try: try: