Skip to content

Commit 00557df

Browse files
Add XML file validation and enhance user output for graph-related CLI commands
1 parent 29b546b commit 00557df

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/cli/cli_handler.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,42 +261,54 @@ def cascade_operations(input_file, output_file, operations):
261261

262262
###### CLI commands (Graph Related) ############################################################
263263
def draw_graph(input_file, output_file):
264+
if os.path.splitext(input_file)[1] != ".xml":
265+
print(f"{Fore.RED}Error: Invalid input file. Please provide a valid XML file.")
266+
return
264267
print(f"{Style.BRIGHT}{Fore.CYAN}Visualizing Graph: {input_file}{Style.RESET_ALL}")
265268
if not os.path.splitext(input_file)[1]:
266269
input_file = f"{input_file}.xml" # Append .xml if no extension is present
267270
print(f"{Fore.LIGHTYELLOW_EX}You forgot to add the extension to the input file :) \nAppending '.xml' to the input file name.")
268271
try:
269272
graph = GraphRepresentation.build_graph(input_file)
270-
GraphVisualizer(graph).visualize(save_path=output_file)
271-
print(f"{Fore.GREEN}Graph Visualization saved to {output_file}")
273+
analyzer:NetworkAnalysis = NetworkAnalysis(graph)
274+
GraphVisualizer(graph).visualize(output_file, most_active_users=analyzer.get_most_active_user(), most_influential_users=analyzer.get_most_influencer_user())
272275
except Exception as e:
273276
print(f"{Fore.RED}Error: did not produce an output file.")
274277

275278
def most_active_user(input_file):
279+
if os.path.splitext(input_file)[1] != ".xml":
280+
print(f"{Fore.RED}Error: Invalid input file. Please provide a valid XML file.")
281+
return
276282
print(f"{Style.BRIGHT}{Fore.CYAN}Finding most active user: {input_file}{Style.RESET_ALL}")
277283
if not os.path.splitext(input_file)[1]:
278284
input_file = f"{input_file}.xml" # Append .xml if no extension is present
279285
print(f"{Fore.LIGHTYELLOW_EX}You forgot to add the extension to the input file :) \nAppending '.xml' to the input file name.")
280286
try:
281287
graph = GraphRepresentation.build_graph(input_file)
282288
user = NetworkAnalysis(graph).get_most_active_user()
283-
print(f"Most active user: {user}")
289+
print(f"Most active user:",*user)
284290
except Exception as e:
285291
print(f"{Fore.RED}Error finding most active user: {e}")
286292

287293
def most_influencer_user(input_file):
294+
if os.path.splitext(input_file)[1] != ".xml":
295+
print(f"{Fore.RED}Error: Invalid input file. Please provide a valid XML file.")
296+
return
288297
print(f"{Style.BRIGHT}{Fore.CYAN}Finding most influential user: {input_file}{Style.RESET_ALL}")
289298
if not os.path.splitext(input_file)[1]:
290299
input_file = f"{input_file}.xml" # Append .xml if no extension is present
291300
print(f"{Fore.LIGHTYELLOW_EX}You forgot to add the extension to the input file :) \nAppending '.xml' to the input file name.")
292301
try:
293302
graph = GraphRepresentation.build_graph(input_file)
294303
user = NetworkAnalysis(graph).get_most_influencer_user()
295-
print(f"Most influential user: {user}")
304+
print(f"Most active user:",*user)
296305
except Exception as e:
297306
print(f"{Fore.RED}Error finding most influential user: {e}")
298307

299308
def mutual_users(input_file, ids):
309+
if os.path.splitext(input_file)[1] != ".xml":
310+
print(f"{Fore.RED}Error: Invalid input file. Please provide a valid XML file.")
311+
return
300312
print(f"{Style.BRIGHT}{Fore.CYAN}Finding mutual users for IDs {ids} in {input_file}{Style.RESET_ALL}")
301313
if not os.path.splitext(input_file)[1]:
302314
input_file = f"{input_file}.xml" # Append .xml if no extension is present
@@ -310,6 +322,9 @@ def mutual_users(input_file, ids):
310322
print(f"{Fore.RED}Error finding mutual users: {e}")
311323

312324
def suggest_users(input_file, user_id):
325+
if os.path.splitext(input_file)[1] != ".xml":
326+
print(f"{Fore.RED}Error: Invalid input file. Please provide a valid XML file.")
327+
return
313328
print(f"{Style.BRIGHT}{Fore.CYAN}Suggesting users for user ID {user_id} in {input_file}{Style.RESET_ALL}")
314329
if not os.path.splitext(input_file)[1]:
315330
input_file = f"{input_file}.xml" # Append .xml if no extension is present

0 commit comments

Comments
 (0)