@@ -41,9 +41,9 @@ def post_on_mastodon(settings, new_posts):
4141 global mt_base_url
4242 mt_base_url = os .getenv ('MASTODON_BASE_URL' )
4343 global mt_username
44- mt_username = os .getenv ('MASTODON_USERNAME' ) # DEPRECATED: to be removed asap
44+ mt_username = os .getenv ('MASTODON_USERNAME' ) # DEPRECATED: to be removed soon
4545 global mt_password
46- mt_password = os .getenv ('MASTODON_PASSWORD' ) # DEPRECATED to be removed asap
46+ mt_password = os .getenv ('MASTODON_PASSWORD' ) # DEPRECATED to be removed soon
4747 global mt_token
4848 mt_token = os .getenv ('MASTODON_OAUTH_TOKEN' )
4949 # Load other details
@@ -53,25 +53,26 @@ def post_on_mastodon(settings, new_posts):
5353 mt_visibility = settings .get ('MASTODON_VISIBILITY' , 'direct' )
5454
5555 # check if config file contains username and password and prompt the user this is deprecated
56- if mt_username != '' or mt_password != '' :
57- logger .warning ('Pelican_fediverse: WARNING: password authentication is DEPRECATED and will be removed soon!\n Please use OAuth token instead...' )
56+ if mt_username or mt_password in globals () :
57+ logger .warning ('Pelican_fediverse: password authentication is DEPRECATED and will be removed soon!\n Please use OAuth token instead...' )
5858
5959 # check if config file contains OAuth token and exit if not
6060 if mt_base_url == '' or mt_token == '' :
6161 logger .warning ('Pelican_fediverse: Mastodon instance URL and/or OAuth token are missing!\n Please check your config file...' )
6262 sys .exit (9 )
6363
64- # if pelicantoot_clientcred.secret does not exist it means we have to create the app on Mastodon
64+ # if pelicantoot_clientcred.secret does not exist it means we have to create our Mastodon app
6565 if os .path .exists ('pelicanfediverse_clientcred.secret' ) == False :
6666 Mastodon .create_app (
6767 'PelicanFediverse' ,
6868 api_base_url = mt_base_url ,
6969 to_file = 'pelicanfediverse_clientcred.secret'
7070 )
7171
72- # Advise the user with an on-screen message. We are ready to publish!
73- build_message = 'Ready to publish on Mastodon: %s (%s)'
72+ # Prepare pubish a message for the user
73+ build_message = 'Articles found to publish on Mastodon: %s (%s)'
7474
75+ # Collect/print information for articles
7576 for article in new_posts :
7677 url = article .get_siteurl () + article .url
7778 title = article .title
@@ -91,19 +92,13 @@ def post_updates(generator, writer):
9192 if article .url not in articleslist :
9293 new_posts .append (article )
9394
94- # we only write the newly found sites to disk if posting them worked. that way we can retry later
95+ # We only write the newly found sites to disk if posting them worked. That way we can retry later
9596 if new_posts :
9697 if post_on_mastodon (generator .settings , new_posts ):
98+ # Log in
9799 mastodon = Mastodon (
98100 client_id = 'pelicanfediverse_clientcred.secret' ,
99- api_base_url = mt_base_url
100- )
101- mastodon .log_in (
102- mt_token ,
103- to_file = 'pelicanfediverse_usercred.secret'
104- )
105- mastodon = Mastodon (
106- access_token = 'pelicanfediverse_usercred.secret' ,
101+ access_token = mt_token ,
107102 api_base_url = mt_base_url
108103 )
109104 # Build the post structure
0 commit comments