Skip to content

Commit e287e1b

Browse files
authored
Merge pull request #40 from hmlendea/auth
Switched to token authentication
2 parents 041b19d + ec1cb32 commit e287e1b

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

main.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ def parse_args():
3535
parser = argparse.ArgumentParser(description="Mastodon RSS Bot")
3636
parser.add_argument("--rss", help="RSS feed URL")
3737
parser.add_argument("--instance", help="Mastodon instance URL")
38-
parser.add_argument("--username", help="Mastodon username (handle)")
39-
parser.add_argument("--email-address", help="Email address for login")
40-
parser.add_argument("--password", help="Base64-encoded password")
38+
parser.add_argument("--username", help="Mastodon username")
39+
parser.add_argument("--access-token", help="Mastodon access token")
4140
parser.add_argument("--tags-to-add", help="Comma-separated tags to add")
4241
parser.add_argument("--days-to-check", type=int, help="How many days back to check")
4342
return parser.parse_args()
@@ -47,8 +46,7 @@ def parse_args():
4746
rss_feed_url = args.rss
4847
mastodon_instance = args.instance
4948
mastodon_username = args.username
50-
mastodon_email_address = args.email_address.lower()
51-
mastodon_password = base64.b64decode(args.password).decode("utf-8")
49+
mastodon_access_token = args.access_token
5250
tags_to_add = args.tags_to_add
5351
days_to_check = args.days_to_check
5452

@@ -68,17 +66,11 @@ def parse_args():
6866

6967
try:
7068
mastodon_api = Mastodon(
71-
client_id = "app_" + mastodon_instance + '.secret',
69+
access_token = mastodon_access_token,
7270
api_base_url = 'https://' + mastodon_instance
7371
)
74-
mastodon_api.log_in(
75-
mastodon_email_address,
76-
password = mastodon_password,
77-
scopes = ['read', 'write'],
78-
to_file = "app_" + mastodon_username + "@" + mastodon_instance + ".secret"
79-
)
80-
except:
81-
print("ERROR: Failed to log " + mastodon_username + " into " + mastodon_instance)
72+
except Exception as ex:
73+
print("ERROR: Failed to log " + mastodon_username + " into " + mastodon_instance + ": " + ex)
8274
sys.exit(1)
8375

8476
feed = feedparser.parse(rss_feed_url)

0 commit comments

Comments
 (0)