social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky
at next 1.0 kB view raw
1import logging 2import sys 3import os 4from typing import Any, Callable 5 6import env 7 8shutdown_hook: list[Callable[[], None]] = [] 9 10logging.basicConfig(stream=sys.stderr, level=logging.DEBUG if env.DEV else logging.INFO) 11LOGGER = logging.getLogger("XPost") 12 13def normalize_service_url(url: str) -> str: 14 if not url.startswith("https://") and not url.startswith("http://"): 15 raise ValueError(f"Invalid service url {url}! Only http/https are supported.") 16 17 return url[:-1] if url.endswith('/') else url 18 19def read_env(data: dict[str, Any]) -> None: 20 keys = list(data.keys()) 21 for key in keys: 22 val = data[key] 23 match val: 24 case str(): 25 if val.startswith('env:'): 26 envval = os.environ.get(val[4:]) 27 if envval is None: 28 del data[key] 29 else: 30 data[key] = envval 31 case dict(): 32 read_env(val) 33 case _: 34 pass