You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

49 lines
1.5 KiB

import os
import re
#import pandas as pd
from arango import ArangoClient, exceptions
from arango.database import StandardDatabase
from dotenv import load_dotenv
class ArangoDB:
def __init__(self, database=None):
"""
Initializes a connection to an ArangoDB database using the configuration
"""
load_dotenv(".env")
host = os.environ['ARANGO_HOSTS']
if database:
db = database
else:
db = os.environ['ARANGO_DB']
username = os.environ['ARANGO_USERNAME']
pwd = os.environ['ARANGO_PWD_LASSE']
# Initialize the database for ArangoDB.
self.client: ArangoClient = ArangoClient(hosts=host)
self.db: StandardDatabase = self.client.db(db, username=username, password=pwd)
def fix_key_name(self, string):
"""
Makes a string a valid ArangoDB key name.
Args:
string (str): The string to fix.
Returns:
str: The fixed string.
"""
string = string.replace("å", "a").replace('ä', 'a').replace('ö', 'o').replace('Å', 'A').replace('Ä', 'A').replace('Ö', 'O')
string = re.sub(r"[^a-zA-Z0-9_\_\-\.\@\(\)\+,=\;\$\!\*\'\%]", "_", string)
encoded_string = string.encode('utf-8')
if len(encoded_string) > 254:
string = encoded_string[:254].decode('utf-8', 'ignore')
return string
arango = ArangoDB()
if __name__ == '__main__':
arango = ArangoDB()
print(arango.db)