social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky
1from pathlib import Path 2from typing import Any, Callable 3 4from cross.service import InputService, OutputService 5 6input_factories: dict[str, Callable[[Path, dict[str, Any]], InputService]] = {} 7output_factories: dict[str, Callable[[Path, dict[str, Any]], OutputService]] = {} 8 9 10def create_input_service(db: Path, data: dict[str, Any]) -> InputService: 11 if "type" not in data: 12 raise ValueError("No `type` field in input data!") 13 type: str = str(data["type"]) 14 del data["type"] 15 16 factory = input_factories.get(type) 17 if not factory: 18 raise KeyError(f"No such input service {type}!") 19 return factory(db, data) 20 21 22def create_output_service(db: Path, data: dict[str, Any]) -> OutputService: 23 if "type" not in data: 24 raise ValueError("No `type` field in input data!") 25 type: str = str(data["type"]) 26 del data["type"] 27 28 factory = output_factories.get(type) 29 if not factory: 30 raise KeyError(f"No such output service {type}!") 31 return factory(db, data)