feat(e621): add environment variable setter

This commit is contained in:
Kat Inskip 2025-02-28 13:12:23 -08:00
parent e426a3ee4e
commit b503cc87a9
Signed by: kat
GPG key ID: 465E64DECEA8CF0F

View file

@ -1,5 +1,6 @@
import requests import requests
import logging import logging
import os
from konawall.custom_print import kv_print from konawall.custom_print import kv_print
from konawall.custom_errors import RequestFailed from konawall.custom_errors import RequestFailed
from konawall.module_loader import add_source from konawall.module_loader import add_source
@ -13,6 +14,9 @@ Turn a list of tags and a count into a list of URLs to download from
:returns: A list of URLs to download from :returns: A list of URLs to download from
""" """
def request_posts(count: int, tags: list, config) -> list: def request_posts(count: int, tags: list, config) -> list:
if "KONAWALL_E621_API_KEY" in os.environ:
api_key = os.environ["KONAWALL_E621_API_KEY"]
else:
api_key = config["e621_api_key"] api_key = config["e621_api_key"]
logging.debug(f"request_posts() called with count={count}, tags=[{', '.join(tags)}]") logging.debug(f"request_posts() called with count={count}, tags=[{', '.join(tags)}]")
# Make sure we get a different result every time by using "order:random" as a tag # Make sure we get a different result every time by using "order:random" as a tag