mt_username = settings.get('MASTODON_USERNAME', '')
global mt_password
mt_password = settings.get('MASTODON_PASSWORD', '')
+ global mt_code
+ mt_code = settings.get('MASTODON_CODE', '')
# check if config file has been duly filled or print an error message and exit
- if mt_base_url == '' or mt_username == '' or mt_password == '':
+ if mt_base_url == '' or ((mt_username == '' or mt_password == '') and mt_code == ''):
logger.warning('Pelican_fediverse: Mastodon access credentials not configured...')
sys.exit(9)
# we only write the newly found sites to disk if posting them worked. that way we can retry later
if new_posts:
if post_on_mastodon(generator.settings, new_posts):
- mastodon = Mastodon(
- client_id = 'pelicanfediverse_clientcred.secret',
- api_base_url = mt_base_url
- )
- mastodon.log_in(
- mt_username,
- mt_password,
- to_file = 'pelicanfediverse_usercred.secret'
- )
+ if not os.path.exists('pelicanfediverse_usercred.secret'):
+ mastodon = Mastodon(
+ client_id = 'pelicanfediverse_clientcred.secret',
+ api_base_url = mt_base_url
+ )
+ if mt_code:
+ mastodon.log_in(
+ code=mt_code,
+ to_file = 'pelicanfediverse_usercred.secret'
+ )
+ else:
+ mastodon.log_in(
+ mt_username,
+ mt_password,
+ to_file = 'pelicanfediverse_usercred.secret'
+ )
mastodon = Mastodon(
access_token = 'pelicanfediverse_usercred.secret',
api_base_url = mt_base_url