|
5 | 5 | import json
|
6 | 6 | from git import Repo
|
7 | 7 |
|
| 8 | +kb_file_path = './data/knowledge_base.json' |
| 9 | + |
8 | 10 | def clean_tmp(dir_path):
|
9 | 11 | """ Clears out all contents of the specified directory except for prebuild.sh """
|
10 | 12 | for item in os.listdir(dir_path):
|
@@ -80,14 +82,14 @@ def parse_markdown():
|
80 | 82 |
|
81 | 83 | def reset_knowledge_base():
|
82 | 84 | """ Resets or initializes the knowledge base JSON file. """
|
83 |
| - with open('./knowledge_base.json', 'w') as output_file: |
| 85 | + with open(kb_file_path, 'w') as output_file: |
84 | 86 | json.dump([], output_file)
|
85 | 87 |
|
86 | 88 | def parse_markdown_file_to_json(file_path):
|
87 | 89 | """ Parses individual markdown file and adds its content to JSON """
|
88 | 90 | try:
|
89 | 91 | # Load existing content if the file exists
|
90 |
| - with open('./knowledge_base.json', 'r') as existing_file: |
| 92 | + with open(kb_file_path, 'r') as existing_file: |
91 | 93 | json_output = json.load(existing_file)
|
92 | 94 | current_id = len(json_output) + 1 # Start ID from the next available number
|
93 | 95 | except (FileNotFoundError, json.JSONDecodeError):
|
@@ -147,15 +149,15 @@ def parse_markdown_file_to_json(file_path):
|
147 | 149 | })
|
148 | 150 | current_id += 1
|
149 | 151 |
|
150 |
| - # Write the augmented JSON output to knowledge_base.json |
151 |
| - with open('./knowledge_base.json', 'w', encoding='utf-8') as output_file: |
| 152 | + # Write the augmented JSON output to ./data/knowledge_base.json |
| 153 | + with open(kb_file_path, 'w', encoding='utf-8') as output_file: |
152 | 154 | json.dump(json_output, output_file, indent=2, ensure_ascii=False)
|
153 | 155 |
|
154 | 156 | def parse_cli_markdown(file_path):
|
155 | 157 | """ Parses CLI-specific markdown files """
|
156 | 158 | try:
|
157 | 159 | # Load existing content if the file exists
|
158 |
| - with open('./knowledge_base.json', 'r') as existing_file: |
| 160 | + with open(kb_file_path, 'r') as existing_file: |
159 | 161 | json_output = json.load(existing_file)
|
160 | 162 | current_id = len(json_output) + 1 # Start ID from the next available number
|
161 | 163 | except (FileNotFoundError, json.JSONDecodeError):
|
@@ -187,8 +189,8 @@ def parse_cli_markdown(file_path):
|
187 | 189 | })
|
188 | 190 | current_id += 1
|
189 | 191 |
|
190 |
| - # Write the augmented JSON output to knowledge_base.json |
191 |
| - with open('./knowledge_base.json', 'w', encoding='utf-8') as output_file: |
| 192 | + # Write the augmented JSON output to data/knowledge_base.json |
| 193 | + with open(kb_file_path, 'w', encoding='utf-8') as output_file: |
192 | 194 | json.dump(json_output, output_file, indent=2, ensure_ascii=False)
|
193 | 195 |
|
194 | 196 | def recursive_parse_directory(root_dir):
|
|
0 commit comments