@@ -354,17 +354,25 @@ def suggest_users(input_file, user_id):
354354 print (f"{ Fore .RED } Error suggesting users: { e } " )
355355
356356def search_posts (input_file , word = None , topic = None ):
357- print (f"Searching posts in { input_file } " )
357+ if os .path .splitext (input_file )[1 ] != ".xml" and os .path .splitext (input_file )[1 ]:
358+ print (f"{ Fore .RED } Error: Invalid input file. Please provide a valid XML file." )
359+ return
360+ print (f"{ Style .BRIGHT } { Fore .CYAN } Searching posts in { input_file } { Style .RESET_ALL } " )
361+ if not os .path .splitext (input_file )[1 ]:
362+ input_file = f"{ input_file } .xml" # Append .xml if no extension is present
363+ print (f"{ Fore .LIGHTYELLOW_EX } You forgot to add the extension to the input file :) \n Appending '.xml' to the input file name." )
358364 try :
359365 searcher = PostSearch (input_file )
360366 if word :
361- results = searcher .search_by_word (word )
362- print (f"Posts containing the word '{ word } ': { results } " )
367+ results = searcher .search_word (word )
368+ print (f"{ Fore .GREEN } Posts containing the word '{ word } ':" )
369+ print (* results , sep = "\n " )
363370 elif topic :
364- results = searcher .search_by_topic (topic )
365- print (f"Posts related to the topic '{ topic } ': { results } " )
371+ results = searcher .search_topic (topic )
372+ print (f"{ Fore .GREEN } Posts related to the topic '{ topic } ':" )
373+ print (* results , sep = "\n " )
366374 except Exception as e :
367- print (f"Error searching posts: { e } " )
375+ print (f"{ Fore . RED } Error searching posts: { e } " )
368376
369377
370378def main ():
0 commit comments