From 938d9d7d6228dfc30bfc99668db296fc4c4886db Mon Sep 17 00:00:00 2001 From: Ari Gato Date: Sat, 3 Aug 2024 19:07:14 +0200 Subject: [PATCH] Get access token from environment variable --- README.md | 2 +- find_posts.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ccb079..1d83790 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ Please find the list of all configuration options, including descriptions, below Option | Required? | Notes | |:----------------------------------------------------|-----------|:------| -|`access-token` | Yes | The access token. If using GitHub action, this needs to be provided as a Secret called `ACCESS_TOKEN`. If running as a cron job or a container, you can supply this option as array, to [fetch posts for multiple users](https://blog.thms.uk/2023/04/muli-user-support-for-fedifetcher) on your instance. | +|`access-token` | Yes | The access token. If using GitHub action, this needs to be provided as a Secret called `ACCESS_TOKEN`. If running as a cron job or a container, you can supply this option as array, to [fetch posts for multiple users](https://blog.thms.uk/2023/04/muli-user-support-for-fedifetcher) on your instance. You may also provide this option as an environment variable starting with `ACCESS_TOKEN`. To fetch posts for multiple users, define multiple environment variables, eg. `ACCESS_TOKEN_USER1=…` and `ACCESS_TOKEN_USER2=…`| |`server`|Yes|The domain only of your mastodon server (without `https://` prefix) e.g. `mstdn.thms.uk`. | |`home-timeline-length` | No | Provide to fetch remote replies to posts in the API-Key owner's home timeline. Determines how many posts we'll fetch replies for. Recommended value: `200`. | `max-bookmarks` | No | Provide to fetch remote replies to any posts you have bookmarked. Determines how many of your bookmarks you want to get replies to. Recommended value: `80`. Requires an access token with `read:bookmarks` scope. diff --git a/find_posts.py b/find_posts.py index c42a32d..13ec1bd 100644 --- a/find_posts.py +++ b/find_posts.py @@ -1488,6 +1488,9 @@ if __name__ == "__main__": logger.critical(f"Config file {arguments.config} doesn't exist") sys.exit(1) + if tokens := [token for envvar, token in os.environ.items() if envvar.startswith("ACCESS_TOKEN")]: + arguments.access_token = tokens + logger.info(f"Starting FediFetcher") if(arguments.server == None or arguments.access_token == None):