import os
import getpass
import subprocess

# Ask the user for their username
username = input("Enter your UNISIPASS username: ")

# Ask the user for their password (hidden input)
# The getpass() function is used to prompt to users using the string prompt and reads the input 
# from the user as Password. The input read defaults to "Password: " is returned to the caller as a string.
password = getpass.getpass("Enter your UNISIPASS password: ")

# Proxy settings
proxy_ip = "172.16.0.200"
proxy_port = "3128"
requirements_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "requirements.txt")

# Create the proxy URL
proxy_url = f"https://{username}:{password}@{proxy_ip}:{proxy_port}"

# Run the pip install command with the proxy
try:

    result = subprocess.run(
        ["pip", "install", f"--proxy={proxy_url}", "-r", requirements_file],
        check=True
    )
    print("✅ Packages installed successfully.")
except subprocess.CalledProcessError:
    print("❌ Error installing packages. Please check your credentials or proxy settings.")