|
|
|
@ -103,22 +103,25 @@ for bridge in config['bridges']:
|
|
|
|
|
logging.info('New post on https://www.facebook.com/' + bridge['facebook_page'] + ' found') |
|
|
|
|
statuses = None |
|
|
|
|
statuses = [] |
|
|
|
|
# Upload image if it exists and no youtube video is to be linked |
|
|
|
|
# Upload images if one at least exists and no youtube video is to be linked |
|
|
|
|
if post['image'] and not (type(post['link']) == str and post['link'].find('youtu') != -1): |
|
|
|
|
# TO DO |
|
|
|
|
# fp = tempfile.TemporaryFile() |
|
|
|
|
# fp.write(b'Hello world!') |
|
|
|
|
# fp.seek(0) |
|
|
|
|
# fp.read() |
|
|
|
|
# fp.close() |
|
|
|
|
# Using curl is necessary, because facebook's secure-image is very restrictive |
|
|
|
|
subprocess.run(['curl', post['image'], '--output', 'tmp.jpg', |
|
|
|
|
medias = [] |
|
|
|
|
for image in post['images']' |
|
|
|
|
# Using curl is necessary, because facebook's secure-image is very restrictive |
|
|
|
|
subprocess.run(['curl', image, '--output', 'tmp.jpg', |
|
|
|
|
"-H", 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0', |
|
|
|
|
"-H", 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', |
|
|
|
|
"-H", 'Accept-Language: de,en-US;q=0.7,en;q=0.3', "--compressed" , |
|
|
|
|
"-H", 'DNT: 1', |
|
|
|
|
"-H", 'Connection: keep-alive', "-H", 'Upgrade-Insecure-Requests: 1']) |
|
|
|
|
media = mastodon.media_post("tmp.jpg") |
|
|
|
|
media = mastodon.media_post("tmp.jpg") |
|
|
|
|
medias.append(media) |
|
|
|
|
|
|
|
|
|
# unwrapp media ids from list of media_posts (dicts) to list of media ids (list of strings) |
|
|
|
|
media_ids = [] |
|
|
|
|
for media in medias |
|
|
|
|
media_ids.append(media['id']) |
|
|
|
|
|
|
|
|
|
# Toot |
|
|
|
|
# If post is too long, split it into main-toot and non-listed replies. |
|
|
|
|
is_main_toot = True |
|
|
|
@ -129,7 +132,7 @@ for bridge in config['bridges']:
|
|
|
|
|
toot = toot_text.replace('https://youtu.be/', 'https://invidious.ggc-project.de/') |
|
|
|
|
if is_main_toot: |
|
|
|
|
if post['image']: |
|
|
|
|
statuses.append(mastodon.status_post(toot, media_ids=media)) |
|
|
|
|
statuses.append(mastodon.status_post(toot, media_ids=media_ids)) |
|
|
|
|
else: |
|
|
|
|
statuses.append(mastodon.status_post(toot)) |
|
|
|
|
is_main_toot = False |
|
|
|
|