-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectionDB.py
33 lines (23 loc) · 962 Bytes
/
connectionDB.py
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
import pandas as pd
from sqlalchemy import create_engine
from dotenv import load_dotenv
import os
load_dotenv()
localhost = os.getenv('LOCALHOST')
port = os.getenv('PORT')
nameDB = os.getenv('DB_NAME')
userDB = os.getenv('DB_USER')
passDB = os.getenv('DB_PASS')
location_file = './Data csv/candidates.csv'
raw_table_database = 'candidates'
names_file = ['first_name', 'last_name', 'email', 'applicant_date', 'country', 'experience_year',
'seniority', 'technology', 'code_challenge_score', 'technical_interview_score']
engine = create_engine(f'postgresql+psycopg2://{userDB}:{passDB}@{localhost}:{port}/{nameDB}')
try:
df = pd.read_csv(location_file, sep=";",names=names_file)
df.to_sql(raw_table_database, engine, if_exists='replace', index=False)
print(f"Tabla '{raw_table_database}' creada y datos subidos exitosamente.")
except Exception as e:
print(f"Error al subir los datos: {e}")
finally:
engine.dispose()