import os import random import sys import time import platform import subprocess import pandas as pd from datetime import datetime from colorama import init, Fore import http.server import socketserver import threading from tqdm import tqdm import shutil import math init() ascii_art = ''' ██╗███████╗███████╗ ██████╗ ██████╗ ██╗ ██╗███╗ ██╗███████╗███████╗██╗ ██╗ ██████╗ ██████╗ ██║██╔════╝██╔════╝ ██╔════╝██╔═══██╗██║ ██║████╗ ██║██╔════╝██╔════╝██║ ██║ ██╔═══██╗██╔══██╗ ██║█████╗ █████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║███████╗█████╗ ██║ ██║ ██║ ██║██████╔╝ ██ ██║██╔══╝ ██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║╚════██║██╔══╝ ██║ ██║ ██║ ██║██╔══██╗ ╚█████╔╝███████╗███████╗ ╚██████╗╚██████╔╝╚██████╔╝██║ ╚████║███████║███████╗███████╗███████╗╚██████╔╝██║ ██║ ╚════╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚══════╝╚══════╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ - A command-line tool for JEE counselling assistance by Ksauraj. ''' author_name = "Ksauraj" version = "v2.0.2" class NoLogRequestHandler(http.server.SimpleHTTPRequestHandler): def log_request(self, code='-', size='-'): pass def display_progress_bar(task_description, steps_completed, total=100, duration=3): """ function which Displays a progress bar. """ with tqdm(total=total, desc=task_description, ncols=100, colour='green',bar_format='{l_bar}{bar} | {n_fmt}/{total_fmt}') as pbar: for _ in range(steps_completed): time.sleep(duration / steps_completed) # Control smoothness of progress pbar.update(1) # Increment the bar by 1 step def delete_output_directory(): """Offers an option to delete the output directory if the user selects the appropriate menu option.""" output_dir = 'output' if os.path.exists(output_dir): print(f"{Fore.MAGENTA}Warning: This will delete all contents in the 'output' directory.") user_input = input(f"{Fore.YELLOW}Press 1 to confirm deletion, or any other key to cancel: {Fore.RESET}") if user_input == '1': shutil.rmtree(output_dir) # Delete the directory and all its contents print(f"{Fore.GREEN}Output directory deleted successfully.{Fore.RESET}") else: print(f"{Fore.YELLOW}Output directory was not deleted.{Fore.RESET}") else: print(f"{Fore.YELLOW}Output directory does not exist.{Fore.RESET}") time.sleep(1) pre_setup() def pre_setup(): #progress bar for loading tool... os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) total=100 steps_completed= int(total*1.0) display_progress_bar("Loadiing Tool...",steps_completed=steps_completed,total=total, duration=0.3) print(Fore.YELLOW + "Select Counseling type:") print(Fore.GREEN + "1." + Fore.BLUE + "JOSAA") print(Fore.GREEN + "2." + Fore.BLUE + "CSAB" + Fore.RESET) print(Fore.GREEN + "3." + Fore.BLUE + "About" + Fore.RESET) print(Fore.GREEN + "4." + Fore.BLUE + "Clean Output Directory" + Fore.RESET) # Added option to clean the output directory print(Fore.GREEN + "5." + Fore.BLUE + "Exit" + Fore.RESET) #adding exit function in main menu option = input("Select Option (1 to 5) : ") #increasing last choice value if option == '1': josaa_rounds_year() elif option == '2': csab_rounds_year() elif option == '3': show_about_section() elif option=='4': delete_output_directory() elif option == '5': #adding exit condition print("Exiting...") #printing exiting exit(0) #calling exit function else: pre_setup() def show_about_section(): print(Fore.CYAN + "\nJEE Counselling Assistant - About\n" + Fore.RESET) print(f"Version: {version}") print(f"Author: {Fore.GREEN}{author_name}{Fore.RESET}") print(f"Acknowledgements: {Fore.GREEN}{author_name}{Fore.RESET}") print("Description: A tool to display colleges based on JEE Mains rank. Get personalized information based on your rank and make informed decisions.") input(Fore.YELLOW + "\nPress Enter to continue to the main menu..." + Fore.RESET) pre_setup() def josaa_rounds_year(): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar of step 1 total = 100 steps_completed = int(total * 0.1) display_progress_bar("STEP 1/10 ", steps_completed=steps_completed, total=total, duration=0.3) applied_filters = {"Counseling Type": "JOSAA"} josaa_round_year = None # initialize print(Fore.YELLOW + "Select JOSAA round year") print(Fore.GREEN + "1." + Fore.BLUE + "2022") print(Fore.GREEN + "2." + Fore.BLUE + "2023") print(Fore.GREEN + "3." + Fore.BLUE + "2024" + Fore.RESET) while josaa_round_year is None: josaa_round_year_sel = input("Select Option (1 to 3): ").strip() if josaa_round_year_sel == "1": josaa_round_year = "2022" elif josaa_round_year_sel == "2": josaa_round_year = "2023" elif josaa_round_year_sel == "3": josaa_round_year = "2024" else: print(Fore.RED + "Invalid input! Please select a number between 1 and 3." + Fore.RESET) applied_filters["Year"] = josaa_round_year josaa_rounds(josaa_round_year, applied_filters) def josaa_rounds(josaa_round_year, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-2 total = 100 steps_completed = int(total * 0.2) display_progress_bar("STEP 2/10 ", steps_completed=steps_completed, total=total, duration=0.3) print(f"{Fore.YELLOW}Select JOSAA round ({josaa_round_year}){Fore.RESET}") if josaa_round_year == "2024": menu_options = [ "Round 1", "Round 2", "Round 3", "Round 4", "Round 5" ] max_option = 5 else: menu_options = [ "Round 1", "Round 2", "Round 3", "Round 4", "Round 5", "Round 6" ] max_option = 6 for i, option in enumerate(menu_options, start=1): print(f"{Fore.GREEN}{i}. {Fore.RESET}{Fore.BLUE}{option}" + Fore.RESET) selected_round = None while selected_round is None: user_input = input(f"Select Option (1 to {max_option}): ").strip() if user_input.isdigit() and 1 <= int(user_input) <= max_option: selected_round = user_input else: print(Fore.RED + f"Invalid input! Please select a number between 1 and {max_option}." + Fore.RESET) applied_filters["Round"] = selected_round csv_files("josaa", selected_round, josaa_round_year, applied_filters) def csab_rounds_year(): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-1 total = 100 steps_completed = int(total * 0.1) display_progress_bar("STEP 1/10 ", steps_completed=steps_completed, total=total, duration=0.3) applied_filters = {"Counseling Type": "CSAB"} csab_round_year = None # initialize print(Fore.YELLOW + "Select CSAB round year") print(Fore.GREEN + "1." + Fore.BLUE + "2021") print(Fore.GREEN + "2." + Fore.BLUE + "2022") print(Fore.GREEN + "3." + Fore.BLUE + "2023") print(Fore.GREEN + "4." + Fore.BLUE + "2024" + Fore.RESET) while csab_round_year is None: csab_round_year_sel = input("Select Option (1 to 4): ").strip() if csab_round_year_sel == "1": csab_round_year = "2021" elif csab_round_year_sel == "2": csab_round_year = "2022" elif csab_round_year_sel == "3": csab_round_year = "2023" elif csab_round_year_sel == "4": csab_round_year = "2024" else: print(Fore.RED + "Invalid input! Please select a number between 1 and 4." + Fore.RESET) applied_filters["Year"] = csab_round_year csab_rounds(csab_round_year, applied_filters) def csab_rounds(csab_round_year, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-2 total = 100 steps_completed = int(total * 0.2) display_progress_bar("STEP 2/10 ", steps_completed=steps_completed, total=total, duration=0.3) print(f"{Fore.YELLOW}Select CSAB round ({csab_round_year})") print(Fore.GREEN + "1." + Fore.BLUE + "Round 1") print(Fore.GREEN + "2." + Fore.BLUE + "Round 2") csab_round = None while csab_round is None: user_input = input(Fore.RESET + "Select Option (1 to 2): ").strip() if user_input in ["1", "2"]: csab_round = user_input else: print(Fore.RED + "Invalid input! Please select 1 or 2." + Fore.RESET) applied_filters["Round"] = csab_round csv_files("csab", csab_round, csab_round_year, applied_filters) def csv_files(type, round, year, applied_filters): # Get path to the temporary folder created by PyInstaller if getattr(sys, 'frozen', False): # If the script is running in a PyInstaller bundle cwd = sys._MEIPASS else: # If the script is running from the original Python file cwd = os.getcwd() if type == "josaa": josaa_rounds = round CSV_FILES = { "ALL": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_all.csv"), "IIITs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_iiits.csv"), "IITs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_iits.csv"), "NITs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_nits.csv"), "GFTIs": os.path.join(cwd, "josaa", f"{year}", f"round_{josaa_rounds}", "ranks_gftis.csv") } josaa_institute_types(CSV_FILES, applied_filters) elif type == "csab": csab_rounds = round csv_path = os.path.join( cwd, "csab", f"{year}", f"round_{csab_rounds}", "ranks.csv") df = pd.read_csv(csv_path) csab_institute_types(df, applied_filters) def csab_institute_types(df, applied_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-3 total = 100 steps_completed = int(total * 0.3) display_progress_bar("STEP 3/10 ", steps_completed=steps_completed, total=total, duration=0.3) print(Fore.YELLOW + "Select Institute type:") print(Fore.GREEN + "1." + Fore.BLUE + "ALL") print(Fore.GREEN + "2." + Fore.BLUE + "IIITs") print(Fore.GREEN + "3." + Fore.BLUE + "NITs") print(Fore.GREEN + "4." + Fore.BLUE + "GFTIs") # loop until valid input option = None institute_type_name = "" while option is None: user_input = input(Fore.RESET + "Select Option (1 to 4): ").strip() if user_input in ["1", "2", "3", "4"]: option = user_input else: print(Fore.RED + "Invalid option! Please select a number between 1 and 4." + Fore.RESET) # filter the dataframe based on the selected option if option == "1": df = df[~df['Institute'].str.contains('Indian Institute of Technology')] institute_type_name = "ALL (IIITs, NITs, GFTIs)" elif option == "2": df = df[df['Institute'].str.contains('Indian Institute of Information Technology')] institute_type_name = "IIITs" elif option == "3": df = df[df['Institute'].str.contains('National Institute of Technology')] institute_type_name = "NITs" elif option == "4": df = df[~df['Institute'].str.contains('National Institute of Technology')] df = df[~df['Institute'].str.contains('Indian Institute of Information Technology')] institute_type_name = "GFTIs" applied_filters["Institute Type"] = institute_type_name main(df, applied_filters) def josaa_institute_types(CSV_FILES, applied_filters): # clear the screen os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) # progress bar for step-3 total = 100 steps_completed = int(total * 0.3) display_progress_bar("STEP 3/10 ", steps_completed=steps_completed, total=total, duration=0.3) print(Fore.YELLOW + "Select Institute type:") print(Fore.GREEN + "1." + Fore.BLUE + "ALL (No IITs Included)") print(Fore.GREEN + "2." + Fore.BLUE + "IIITs") print(Fore.GREEN + "3." + Fore.BLUE + "NITs") print(Fore.GREEN + "4." + Fore.BLUE + "GFTIs") print(Fore.GREEN + "5." + Fore.BLUE + "IITs") # loop until valid input college_type = None option = None while option is None: user_input = input(Fore.RESET + "Select Option (1 to 5): ").strip() if user_input in ["1", "2", "3", "4", "5"]: option = user_input if option == "1": college_type = "ALL" elif option == "2": college_type = "IIITs" elif option == "3": college_type = "NITs" elif option == "4": college_type = "GFTIs" elif option == "5": college_type = "IITs" else: print(Fore.RED + "Invalid option! Please select a number between 1 and 5." + Fore.RESET) applied_filters["Institute Type"] = college_type # read the csv file based on the selected college type csv_path = CSV_FILES[college_type] df = pd.read_csv(csv_path) if option == "1": # Remove all IITs occurrence if "ALL" option was chosen df = df[~df['Institute'].str.contains('Indian Institute of Technology')] main(df, applied_filters) elif option == "5": # fix ranks with strings in them df['Closing Rank'] = df['Closing Rank'].str.extract(r'(\d+)').astype(float) df['Opening Rank'] = df['Opening Rank'].str.extract(r'(\d+)').astype(int) main(df, applied_filters) else: main(df, applied_filters) def filter_programs(institute_df, current_filters): os.system("cls" if os.name == "nt" else "clear") print(Fore.GREEN + ascii_art) #progress bar for step-4 total=100 steps_completed= int(total*0.4) display_progress_bar("STEP 4/10 ",steps_completed=steps_completed,total=total, duration=0.3) print("Note: Programs marked with '*' will display all the programs similar to them.") print("Select Program:") print(Fore.GREEN + "1." + Fore.BLUE + "All") print(Fore.GREEN + "2." + Fore.BLUE + "Computer Science and Engineering*") print(Fore.GREEN + "3." + Fore.BLUE + "Artificial Intelligence and Data Science*") print(Fore.GREEN + "4." + Fore.BLUE + "Electronics and Communication Engineering*") print(Fore.GREEN + "5." + Fore.BLUE + "Information Technology*") print(Fore.GREEN + "6." + Fore.BLUE + "Mechanical Engineering*") print(Fore.GREEN + "7." + Fore.BLUE + "Civil Engineering*") print(Fore.GREEN + "8." + Fore.BLUE + "Electrical Engineering*") print(Fore.GREEN + "9." + Fore.BLUE + "Data Science and Engineering*") print(Fore.GREEN + "10." + Fore.BLUE + "Biotechnology*") print(Fore.GREEN + "11." + Fore.BLUE + "Chemical Engineering*") print(Fore.GREEN + "12." + Fore.BLUE + "Smart Manufacturing*") print(Fore.GREEN + "13." + Fore.YELLOW + "Check Next Page" + Fore.RESET) print("") program_choices = { 1: 'All', 2: 'Computer Science and Engineering', 3: 'Artificial Intelligence and Data Science', 4: 'Electronics and Communication Engineering', 5: 'Information Technology', 6: 'Mechanical Engineering', 7: 'Civil Engineering', 8: 'Electrical Engineering', 9: 'Data Science and Engineering', 10: 'Biotechnology', 11: 'Chemical Engineering', 12: 'Smart Manufacturing' } program_input = input("Choose Option(s) (separated by space): ") program_choices_list = program_input.split() filtered_df = institute_df selected_program_names = [] if '1' in program_choices_list: selected_program_names.append("All") else: # Build a list of selected program names for choice in program_choices_list: if choice.isdigit() and int(choice) in program_choices: selected_program_names.append(program_choices[int(choice)]) # Filter the dataframe if selected_program_names: filtered_df = institute_df[institute_df["Academic Program Name"].str.contains( '|'.join(selected_program_names))] current_filters["Program"] = ", ".join(selected_program_names) if len(filtered_df) == 0: print( Fore.RED + "No programs found matching the selected options." + Fore.RESET) return filtered_df # This part for page 2 can be simplified or adjusted as needed if '13' in program_choices_list: os.system("cls" if os.name == "nt" else "clear") programs = filtered_df["Academic Program Name"].unique() for i, program in enumerate(programs, start=14): print(f"{Fore.GREEN}{i}. {Fore.BLUE}{program}{Fore.RESET}") program_choice = int(input("Choose Option: ")) if program_choice >= 14 and program_choice < 14 + len(programs): program = programs[program_choice - 14] filtered_df = filtered_df[filtered_df["Academic Program Name"] == program] current_filters["Program"] = program # Update with the specific choice else: print(Fore.RED + "Invalid choice. Please try again." + Fore.RESET) return filtered_df return filtered_df def display_df_web(df, heading, subheading, applied_filters=None): output_dir = 'output' if not os.path.exists(output_dir): os.makedirs(output_dir) # create a unique filename based on the current date and time filename = os.path.join( output_dir, f"{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.html") # convert the DataFrame to an HTML table html_table = df.to_html(index=False, classes='table',table_id="tableID") # Prepare the filters section as HTML filters_html = "" if applied_filters: filters_html += "