social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky
at next 1.3 kB view raw
1from typing import Any 2 3from database.connection import DatabasePool 4from registry import input_factories, output_factories 5 6 7class LazyFactory: 8 def __init__(self, module_path: str, class_name: str, options_class_name: str): 9 self.module_path: str = module_path 10 self.class_name: str = class_name 11 self.options_class_name: str = options_class_name 12 13 def __call__(self, db: DatabasePool, d: dict[str, Any]): 14 module = __import__( 15 self.module_path, fromlist=[self.class_name, self.options_class_name] 16 ) 17 service_class = getattr(module, self.class_name) 18 options_class = getattr(module, self.options_class_name) 19 return service_class(db, options_class.from_dict(d)) 20 21def bootstrap(): 22 input_factories["mastodon-wss"] = LazyFactory( 23 "mastodon.input", "MastodonInputService", "MastodonInputOptions" 24 ) 25 input_factories["misskey-wss"] = LazyFactory( 26 "misskey.input", "MisskeyInputService", "MisskeyInputOptions" 27 ) 28 input_factories["bluesky-jetstream"] = LazyFactory( 29 "bluesky.input", "BlueskyJetstreamInputService", "BlueskyJetstreamInputOptions" 30 ) 31 output_factories['stderr'] = LazyFactory( 32 "util.dummy", "StderrOutputService", "DummyOptions" 33 )