From 965771fb0d85ddb27dc6c5dd7df822d1fb318286 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Sat, 15 Mar 2025 16:35:39 +0800 Subject: refactor: clean up code formatting and add new PluginManager class --- src/conventionalrp/core/__init__.py | 2 +- src/conventionalrp/core/parser.py | 7 ++++--- src/conventionalrp/core/processor.py | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src/conventionalrp/core') diff --git a/src/conventionalrp/core/__init__.py b/src/conventionalrp/core/__init__.py index d63b2a9..cc59ba4 100644 --- a/src/conventionalrp/core/__init__.py +++ b/src/conventionalrp/core/__init__.py @@ -1,4 +1,4 @@ # FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/core/__init__.py """ This file initializes the core module of the conventionalrp SDK. -""" \ No newline at end of file +""" diff --git a/src/conventionalrp/core/parser.py b/src/conventionalrp/core/parser.py index 266506b..d5b91da 100644 --- a/src/conventionalrp/core/parser.py +++ b/src/conventionalrp/core/parser.py @@ -2,18 +2,19 @@ import json import re from pathlib import Path + class Parser: def __init__(self): self.rules = [] - def load_rules(self, rules_path : str): + def load_rules(self, rules_path: str): """Load parsing rules.""" if not Path(rules_path).exists(): raise FileNotFoundError(f"No such file or directory: {rules_path} ") with open(rules_path, "r", encoding="utf-8") as f: file_content = f.read() - + rules = json.loads(file_content) # validation rule format @@ -53,4 +54,4 @@ class Parser: else: parsed_data.append({"content": line.strip(), "type": "unknown"}) - return parsed_data \ No newline at end of file + return parsed_data diff --git a/src/conventionalrp/core/processor.py b/src/conventionalrp/core/processor.py index 40033cf..4e2f573 100644 --- a/src/conventionalrp/core/processor.py +++ b/src/conventionalrp/core/processor.py @@ -17,23 +17,28 @@ class Processor: def generate_output(self, processed_data, format_type): # Implement output generation logic based on format_type - if format_type == 'json': + if format_type == "json": return self.generate_json_output(processed_data) - elif format_type == 'html': + elif format_type == "html": return self.generate_html_output(processed_data) - elif format_type == 'markdown': + elif format_type == "markdown": return self.generate_markdown_output(processed_data) else: raise ValueError("Unsupported format type") def generate_json_output(self, processed_data): import json + return json.dumps(processed_data) def generate_html_output(self, processed_data): # Implement HTML output generation - return "" + "".join(f"
{data}
" for data in processed_data) + "" + return ( + "" + + "".join(f"{data}
" for data in processed_data) + + "" + ) def generate_markdown_output(self, processed_data): # Implement Markdown output generation - return "\n".join(f"- {data}" for data in processed_data) \ No newline at end of file + return "\n".join(f"- {data}" for data in processed_data) -- cgit v1.2.3-70-g09d2