|
|
|
@ -34,28 +34,28 @@ database_filename = 'database.pkl'
|
|
|
|
|
config_filename = 'config.json' |
|
|
|
|
mastodon_character_limit_default = 500 |
|
|
|
|
|
|
|
|
|
logging.info('Execute mastaface at', datetime.now()) |
|
|
|
|
logging.info('Execute mastaface at ' + datetime.now().strftime("%Y-%m-%d, %H:%M:%S") ) |
|
|
|
|
|
|
|
|
|
try: # Open config file and verify it is valid json |
|
|
|
|
with open(config_filename, 'r') as f: |
|
|
|
|
logging.debug('found config:', config_filename) |
|
|
|
|
logging.debug('found config: ' + config_filename) |
|
|
|
|
config = json.load(f) |
|
|
|
|
except Exception as e: |
|
|
|
|
logging.error(e) |
|
|
|
|
exit |
|
|
|
|
logging.info('Loaded config from', config_filename) |
|
|
|
|
logging.info('Loaded config from ' + config_filename) |
|
|
|
|
|
|
|
|
|
# Get history-database |
|
|
|
|
# Check if database file exists |
|
|
|
|
if path.exists(database_filename): |
|
|
|
|
logging.info('found briding-history-database at', database_filename) |
|
|
|
|
logging.info('found briding-history-database at ' + database_filename) |
|
|
|
|
try: |
|
|
|
|
database = pickle.load( open( database_filename, "rb" ) ) |
|
|
|
|
except Exception as e: |
|
|
|
|
logging.error(e) |
|
|
|
|
logging.info('Loaded bridging-history-database') |
|
|
|
|
else: |
|
|
|
|
logging.warning('No bridging-history-database found at', database_filename) |
|
|
|
|
logging.warning('No bridging-history-database found at' + database_filename) |
|
|
|
|
# initialize database |
|
|
|
|
database = {} |
|
|
|
|
|
|
|
|
@ -75,7 +75,7 @@ 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 |
|
|
|
|
# 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 |
|
|
|
@ -87,7 +87,7 @@ for bridge in config['bridges']:
|
|
|
|
|
# Last post has been updated, so first delete the old toot |
|
|
|
|
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') |
|
|
|
|
logging.debug('Deleted post ' + str(status['id']) + ' on mastodon because of facebook edit') |
|
|
|
|
statuses = None |
|
|
|
|
statuses = [] |
|
|
|
|
# Upload image if it exists |
|
|
|
@ -114,25 +114,25 @@ for bridge in config['bridges']:
|
|
|
|
|
else: |
|
|
|
|
statuses.append(mastodon.status_post(toot)) |
|
|
|
|
is_main_toot = False |
|
|
|
|
logging.info('Bridged post', post['post_id'], 'to', statuses[-1]['id'] ) |
|
|
|
|
logging.info('Bridged post' + str(post['post_id']) + ' to ', str(statuses[-1]['id']) ) |
|
|
|
|
else: |
|
|
|
|
statuses.append(mastodon.status_post(toot, in_reply_to_id = statuses[-1], visibility = 'unlisted')) |
|
|
|
|
# After bridging was successfull update database of bridging history |
|
|
|
|
# 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'] ) |
|
|
|
|
logging.info('No updates to bridge for'+ bridge['facebook_page'] ) |
|
|
|
|
except Exception as e: |
|
|
|
|
logging.error('Error bridging', bridge['facebook_page']) |
|
|
|
|
logging.error('Error bridging' + bridge['facebook_page']) |
|
|
|
|
logging.debug(e) |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
# Save database to file |
|
|
|
|
try: |
|
|
|
|
pickle.dump(database, open(database_filename, "wb" )) |
|
|
|
|
logging.debug('updated bridging-history-database at', database_filename) |
|
|
|
|
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) |
|
|
|
|
logging.error('error writing bridging-history-database at' + database_filename) |
|
|
|
|
logging.debug(print(e)) |