From 80b74f79dfbfa9afb845172a5ea84110d75f1bc8 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Thu, 13 Mar 2025 01:01:20 +0800 Subject: refactor(project)!: first implementation of the Conventional Role Play SDK with core components, renderers, extractors, and example usage. --- examples/basic_usage.py | 31 +++++++++++++++++++++++++++++++ examples/custom_plugin.py | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/basic_usage.py create mode 100644 examples/custom_plugin.py (limited to 'examples') diff --git a/examples/basic_usage.py b/examples/basic_usage.py new file mode 100644 index 0000000..e2209da --- /dev/null +++ b/examples/basic_usage.py @@ -0,0 +1,31 @@ +from trpg_log_processor.core.parser import Parser +from trpg_log_processor.core.processor import Processor +from trpg_log_processor.extractors.rule_extractor import RuleExtractor +from trpg_log_processor.renderers.html_renderer import HTMLRenderer + +def main(): + # Initialize the parser and load rules + parser = Parser() + parser.load_rules('path/to/rules.json') + + # Parse the TRPG log + log_data = "Your TRPG log data here" + parsed_tokens = parser.parse_log(log_data) + + # Initialize the rule extractor + extractor = RuleExtractor() + rules = extractor.extract('path/to/rules.json') + + # Process the parsed tokens + processor = Processor() + processed_data = processor.process_tokens(parsed_tokens, rules) + + # Render the output in HTML format + renderer = HTMLRenderer() + output = renderer.render(processed_data) + + # Print or save the output + print(output) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/examples/custom_plugin.py b/examples/custom_plugin.py new file mode 100644 index 0000000..74a0bcc --- /dev/null +++ b/examples/custom_plugin.py @@ -0,0 +1,25 @@ +from trpg_log_processor.plugins.plugin_manager import PluginManager + +class CustomPlugin: + def __init__(self): + self.name = "Custom Plugin" + + def process(self, data): + # Custom processing logic + processed_data = data.upper() # Example transformation + return processed_data + +def main(): + plugin_manager = PluginManager() + custom_plugin = CustomPlugin() + + plugin_manager.register_plugin(custom_plugin) + + # Example data to process + data = "This is a sample TRPG log." + result = custom_plugin.process(data) + + print(f"Processed Data: {result}") + +if __name__ == "__main__": + main() \ No newline at end of file -- cgit v1.2.3-70-g09d2