From d0fc2f7ca7c1840672a605535dd669e5cb7037b2 Mon Sep 17 00:00:00 2001 From: Ari Gato Date: Fri, 9 Aug 2024 12:53:25 +0200 Subject: [PATCH] Allow all settings to be set via env variables --- README.md | 6 ++++-- find_posts.py | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1d837903..0c73ef31 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,13 @@ If you configure FediFetcher this way, it'll fetch missing remote replies to the #### Advanced Options -Please find the list of all configuration options, including descriptions, below: +Below is a list of all configuration options, including their descriptions. +Please note that configuration options may also be specified as environment variables starting with the prefix `FF_`, case-insensitive, and with `-` replaced with `_`. +For example `max-favourites` can be set via `FF_MAX_FAVOURITES` or `ff_max_favourites`) 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. 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=…`| +|`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. To set tokens for multiple users using environment variables, define multiple environment variables with `FF_ACCESS_TOKEN` prefix, eg. `FF_ACCESS_TOKEN_USER1=…` and `FF_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 13ec1bd1..e64503bb 100644 --- a/find_posts.py +++ b/find_posts.py @@ -1488,7 +1488,12 @@ def fetch_timeline_context(timeline_posts, token, parsed_urls, seen_hosts, seen_ 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")]: + for name, value in os.environ.items(): + if name.lower().startswith("ff_"): + setattr(arguments, name[3:].lower(), value) + + # remains special-cased for specifying multiple tokens + if tokens := [token for envvar, token in os.environ.items() if envvar.lower().startswith("FF_ACCESS_TOKEN")]: arguments.access_token = tokens logger.info(f"Starting FediFetcher")