Browse Source

add multiple images support (up to four images)

master
André Menrath 2 years ago
parent
commit
8757319b10
  1. 7
      README.md
  2. 25
      mastaface.py

7
README.md

@ -1,17 +1,14 @@
** This is early alpha and more like a proof of concept **
## Mastaface
## Mastaface - A simple Facebook to Mastodon Bridge
Mastaface scrapes the last post of a public facebook page and bridges it to mastodon.
## Features:
- splits facebook posts with are longer than the character limit into serveral toots (replies)
- checks only for the last post, so if you miss one, you're out of luck
- only cross-posts the main-image of a facebook post
- only cross-posts up to the first four images of a facebook post
Please be sure to get the permission **before** mirroring some facebook site.
## Dependencies
### OS:
- curl

25
mastaface.py

@ -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

Loading…
Cancel
Save