-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (32 loc) · 1.11 KB
/
utils.py
File metadata and controls
35 lines (32 loc) · 1.11 KB
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
import json
import psycopg2
def load_config(config_path):
'''
Function to load configuration from a JSON file
'''
with open(config_path, 'r') as file:
config = json.load(file)
return config
def get_db_connection(database_credentials):
'''
Function to establish a connection to the PostgreSQL database
'''
try:
DB_CONN_STRING = "dbname='{db_name}' port='{port}' user='{user}' password='{password}' host='{host}'".format(
db_name=database_credentials['db_name'],
host=database_credentials['host'],
port=database_credentials['port'],
user=database_credentials['username'],
password=database_credentials['password']
)
conn = psycopg2.connect(DB_CONN_STRING)
cur = conn.cursor()
return conn, cur
except Exception as exp:
print(f"Error connecting to the database: {exp}")
return
def kafka_delivery_report(err, msg):
if err is not None:
print(f'Message delivery failed: {err}')
else:
print(f'Message delivered to {msg.topic()} [{msg.partition()}]')