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