Browse Source

bux fixes

master
hfte 2 years ago
parent
commit
2d08426c80
  1. 33
      mastaface.py

33
mastaface.py

@ -27,7 +27,7 @@ from facebook_scraper import get_posts
from mastodon import Mastodon
from vendor import split_tweet
logging.basicConfig(filename='mastaface.log',level=logging.ERROR)
logging.basicConfig(filename='mastaface.log',level=logging.DEBUG)
# Global variables
database_filename = 'database.pkl'
@ -75,11 +75,17 @@ for bridge in config['bridges']:
else:
mastodon_character_limit = mastodon_character_limit_default
toots_text = split_tweet.split_tweet(post['post_text'], mastodon_character_limit)
# Check if current bridge, already exists in database
if bridge['facebook_page'] not in database:
database[bridge['facebook_page']] = {}
database[bridge['facebook_page']]['last_post_id'] = None
database[bridge['facebook_page']]['last_edited'] = None
database[bridge['facebook_page']]['mastodon_statuses'] = None
# Check if there is a new post, or the last one has been edited
if post['time'] != database[config['facebook_page']]['last_edited']:
if post['post_id'] == database[config['facebook_page']]['last_post_id']:
if post['time'] != database[bridge['facebook_page']]['last_edited']:
if post['post_id'] == database[bridge['facebook_page']]['last_post_id']:
# Last post has been updated, so first delete the old toot
for status in database[config['facebook_page']]['mastodon_statuses']:
for status in database[bridge['facebook_page']]['mastodon_statuses']:
Mastodon.status_delete(status['id'])
logging.debug('Deleted post', status['id'], 'on mastodon because of facebook edit')
statuses = None
@ -110,18 +116,23 @@ for bridge in config['bridges']:
is_main_toot = False
logging.info('Bridged post', post['post_id'], 'to', statuses[-1]['id'] )
else:
statuses.append(mastodon.status_post(toot), in_reply_to_id = statuses[-1], visibility = 'unlisted' )
statuses.append(mastodon.status_post(toot, in_reply_to_id = statuses[-1], visibility = 'unlisted'))
# After bridging was successfull update database of bridging history
database[bridge['facebook_page']] = {}
database[bridge['facebook_page']]['last_post_id'] = post['post_id']
database[bridge['facebook_page']]['last_edited'] = post['time']
database[bridge['facebook_page']]['mastodon_statuses'] = statuses
else:
logging.info('No updates to bridge for', ['facebook_page'] )
except Exception as e:
logging.error('Error bridging', bridge['facebook_page'])
logging.debug(e)
continue
# After bridging was successfull update database of bridging history
database[config['facebook_page']]['last_post_id'] = post['post_id']
database[config['facebook_page']]['last_edited'] = post['time']
database[config['facebook_page']]['mastodon_statuses'] = statuses
# Save database to file
pickle.dump(database, open(database_filename, "wb" ))
logging.debug('updated bridging-history-database at', database_filename)
try:
pickle.dump(database, open(database_filename, "wb" ))
logging.debug('updated bridging-history-database at', database_filename)
except Exception as e:
logging.error('error writing bridging-history-database at', database_filename)
logging.debug(e)
Loading…
Cancel
Save