File size: 2,718 Bytes
f55c453
097744c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f55c453
480d518
097744c
 
 
480d518
097744c
 
53d57fc
5b2e817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6ef950
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
from firebase_admin import storage

import os
from dotenv import load_dotenv

# load the environment variables
load_dotenv()

firebase_url_storageBucket = os.getenv("FIREBASE_URL_STORAGEBUCKET")

# get credentials from .env
credential_firebase = {
    "type": os.getenv("FIREBASE_TYPE"),
    "project_id": os.getenv("FIREBASE_PROJECT_ID"),
    "private_key_id": os.getenv("FIREBASE_PRIVATE_KEY_ID"),
    "private_key": os.getenv("FIREBASE_PRIVATE_KEY").replace('\\n', '\n'),
    "client_email": os.getenv("FIREBASE_CLIENT_EMAIL"),
    "client_id": os.getenv("FIREBASE_CLIENT_ID"),
    "auth_uri": os.getenv("FIREBASE_AUTH_URI"),
    "token_uri": os.getenv("FIREBASE_TOKEN_URI"),
    "auth_provider_x509_cert_url": os.getenv("FIREBASE_AUTH_PROVIDER_X509_CERT_URL"),
    "client_x509_cert_url": os.getenv("FIREBASE_CLIENT_X509_CERT_URL"),
    "universe_domain": os.getenv("FIREBASE_UNIVERSE_DOMAIN")
}

# check if firebase is not initialized
if not firebase_admin._apps:
    # Initialize the app with a service account, granting admin privileges
    cred = credentials.Certificate(credential_firebase)
    firebase_admin.initialize_app(cred, {
        'storageBucket': firebase_url_storageBucket
    })

# Initialize Firestore
firebase_db = firestore.client()
print("Firestore connected")

# Initialize Storage
firebase_bucket = storage.bucket(app=firebase_admin.get_app())
print("Storage connected")

# check if have question_tests collection
if "question_tests" not in [collection.id for collection in firebase_db.collections()]:
    # Create a collection
    firebase_db.collection("question_tests").add({"question_tests_description": "test", "question_tests_role": "test", "question_tests_url": "test"})
    print("Collection question_tests created")

# check if have cvs collection
if "cvs" not in [collection.id for collection in firebase_db.collections()]:
    # Create a collection
    firebase_db.collection("cvs").add({"name_candidate": "test", "apply_position": "test", "cv_url": "test"})
    print("Collection cvs created")

# check if have jds collection
if "jds" not in [collection.id for collection in firebase_db.collections()]:
    # Create a collection
    firebase_db.collection("jds").add({"position_applied_for": "test","jd_url": "test"})
    print("Collection jds created")

# check if have rag_question_tests collection
if "rag_question_tests" not in [collection.id for collection in firebase_db.collections()]:
    # Create a collection
    firebase_db.collection("rag_question_tests").add({"id_jd": "test","question_generator_tests_url": "test"})
    print("Collection rag_question_tests created")