Skip to content

Commit 894e44d

Browse files
committed
2 parents a871180 + 091ba9c commit 894e44d

4 files changed

Lines changed: 62 additions & 6 deletions

File tree

app.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import sys
2+
from colorama import init, Fore, Style
3+
from main import launch_gui, launch_cli
4+
5+
# Initialize colorama
6+
init(autoreset=True)
7+
8+
def print_help():
9+
help_text = f"""
10+
{Fore.YELLOW}{"Nodescope: An XML Editor and Visualizer".center(60)}{Style.RESET_ALL}
11+
12+
{Fore.CYAN}Usage:{Style.RESET_ALL}
13+
Select the desired mode by entering the corresponding number.
14+
15+
{Fore.CYAN}Modes:{Style.RESET_ALL}
16+
{Fore.GREEN}1.{Style.RESET_ALL} GUI - Launch the graphical user interface.
17+
{Fore.GREEN}2.{Style.RESET_ALL} CLI - Launch the command-line interface.
18+
{Fore.GREEN}3.{Style.RESET_ALL} Help - Show this help information.
19+
{Fore.GREEN}4.{Style.RESET_ALL} Exit - Exit the application.
20+
21+
{Fore.CYAN}Instructions:{Style.RESET_ALL}
22+
- Enter the number corresponding to your choice and press Enter.
23+
- For example, enter '1' to launch the GUI.
24+
"""
25+
print(help_text)
26+
27+
def app():
28+
print_help()
29+
30+
while True:
31+
try:
32+
choice = input(f"{Fore.GREEN}Enter your choice (1/2/3/4): {Style.RESET_ALL}").strip()
33+
if choice == '1':
34+
print(f"{Fore.BLUE}Launching GUI...{Style.RESET_ALL}")
35+
launch_gui()
36+
break # Exit after launching GUI
37+
elif choice == '2':
38+
print(f"{Fore.BLUE}Launching CLI...{Style.RESET_ALL}")
39+
launch_cli()
40+
break # Exit after launching CLI
41+
elif choice == '3':
42+
print_help()
43+
elif choice == '4':
44+
print(f"{Fore.LIGHTRED_EX}Exiting application. Goodbye!{Style.RESET_ALL}")
45+
sys.exit(0)
46+
else:
47+
print(f"{Fore.RED}Invalid choice. Please enter 1, 2, 3, or 4.{Style.RESET_ALL}")
48+
except KeyboardInterrupt:
49+
print(f"\n{Fore.LIGHTRED_EX}Exiting application. Goodbye!{Style.RESET_ALL}")
50+
sys.exit(0)
51+
except Exception as e:
52+
print(f"{Fore.RED}An unexpected error occurred: {e}{Style.RESET_ALL}")
53+
54+
if __name__ == "__main__":
55+
app()

src/graph/graph_representation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ def parse_xml_to_graph(xml_file_path):
119119
name=_get_value(user_data, "<name>", "</name>"),
120120
)
121121
adjacency_list[user.id] = []
122-
connections[user.id] = set()
122+
if user.id not in connections:
123+
connections[user.id] = set()
123124
# Parse posts
124125
posts_data = _get_values(user_data, "<post>", "</post>")
125126
for post_data in posts_data:
@@ -174,4 +175,4 @@ def _get_values(data, start_tag, end_tag):
174175
# graph = GraphRepresentation.build_graph(r"path to xml file")
175176
# print(graph.adjacency_list)
176177
# print(graph.connections)
177-
# # print(graph.get_user_connections(5))
178+
# print(graph.get_user_connections(5))

src/modules/xml_compressor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ def compress(self, output_path):
1313
file.write(compressed_data)
1414

1515
# Usage
16-
compressor = XMLCompressor('../../samples/large_sample.xml')
17-
compressor.compress('../../samples/output.compressed')
16+
# compressor = XMLCompressor('../../samples/large_sample.xml')
17+
# compressor.compress('../../samples/output.compressed')
1818

src/modules/xml_decompressor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ def decompress(self, output_path):
4646

4747

4848
# Usage
49-
decompressor = XMLDecompressor(r'../samples/compressed.xml')
50-
decompressor.decompress(r'../samples/decompressed.xml')
49+
# decompressor = XMLDecompressor(r'../samples/compressed.xml')
50+
# decompressor.decompress(r'../samples/decompressed.xml')

0 commit comments

Comments
 (0)