-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (41 loc) · 1.67 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from core.file_handler import load_file, save_file
from core.core import Core
def main():
print("Welcome to the Text Processing Tool!")
# Initialize the Core
core = Core("plugins")
# Load text file
file_path = input("Enter the path to the text file: ").strip()
original_text = load_file(file_path)
if not original_text:
print("Failed to load the file. Exiting.")
return
# List plugins
print("\nAvailable Plugins:")
core.list_plugins()
# Allow multiple plugin selection
print("\nSelect one or more plugins to apply by entering their numbers separated by commas (e.g., 1,3,5):")
choices = input("Enter your choices: ").strip().split(',')
# Validate choices
try:
choices = [int(choice) - 1 for choice in choices]
plugin_names = [list(core.plugins.keys())[choice] for choice in choices if choice in range(len(core.plugins))]
except (ValueError, IndexError):
print("Invalid choices. Exiting.")
return
# Apply selected plugins to the original text
results = []
for plugin_name in plugin_names:
print(f"\nApplying plugin: {plugin_name}")
result = core.apply_plugin(plugin_name, original_text) # Always use the original text
results.append(f"Result after '{plugin_name}':\n{result}")
print(results[-1])
# Save all results
output_path = input("\nEnter the path and/or name to save the plugin results: ").strip()
try:
save_file(output_path, '\n\n'.join(results))
print(f"Processed results saved to {output_path}.")
except Exception as e:
print(f"Error saving file: {e}")
if __name__ == "__main__":
main()