import os try: from arango import ArangoClient except ModuleNotFoundError: import subprocess subprocess.run(["pip", "install", "python-arango"]) from arango import ArangoClient try: from dotenv import load_dotenv except ModuleNotFoundError: import subprocess subprocess.run(["pip", "install", "python-dotenv"]) from dotenv import load_dotenv def get_env(): """ Initializes a connection to an ArangoDB database and retrieves all documents from the 'enviroment' collection. This function attempts to load environment variables from a .env file to get the ArangoDB password. If the .env file is not found, it prompts the user to input the password manually. It then connects to the ArangoDB instance using the provided credentials and returns the first document from the 'enviroment' collection. Returns: dict: The first document from the 'enviroment' collection in the ArangoDB database. Raises: FileNotFoundError: If the .env file is not found. KeyError: If the 'ARANGO_PWD_ENV_MANAGER' environment variable is not set. """ try: load_dotenv(".env") pwd = os.environ['ARANGO_PWD_ENV_MANAGER'] except FileNotFoundError: print("No .env file found.") pwd = input("Enter the ArangoDB password for the user 'env_manager': ") host ="https://arango.lasseedfast.se" username = "env_manager" db='div' # Initialize the database for ArangoDB. db = ArangoClient(hosts=host).db(db, username=username, password=pwd) env_doc = db.collection('enviroment').all().next() # Set the environment variables for key, value in env_doc.items(): if isinstance(value, dict): continue os.environ[key] = str(value) return env_doc # Retrieve and set environment variables env = get_env()