AIdeaText commited on
Commit
84ec5fc
1 Parent(s): 28aefca

Update modules/db_connection.py

Browse files
Files changed (1) hide show
  1. modules/db_connection.py +19 -16
modules/db_connection.py CHANGED
@@ -1,20 +1,23 @@
1
- #db_connection.py
2
  import os
3
- from azure.identity import ClientSecretCredential
4
- import pymssql
5
 
6
- def get_db_connection():
7
- server = 'aideatexdb.database.windows.net'
8
- database = 'textdb'
9
- client_id = os.getenv('AZURE_CLIENT_ID')
10
- client_secret = os.getenv('AZURE_CLIENT_SECRET')
11
- tenant_id = os.getenv('AZURE_TENANT_ID')
12
 
13
- credential = ClientSecretCredential(tenant_id, client_id, client_secret)
14
- token = credential.get_token("https://database.windows.net/.default")
 
 
15
 
16
- conn = pymssql.connect(server=server,
17
- database=database,
18
- user=client_id+'@'+server,
19
- password=token.token)
20
- return conn
 
 
 
 
 
 
 
1
+ import requests
2
  import os
 
 
3
 
4
+ def call_azure_function(operation, data):
5
+ function_url = os.getenv('AZURE_FUNCTION_URL')
6
+ api_key = os.getenv('AZURE_FUNCTION_API_KEY') # Si está utilizando una clave de API
 
 
 
7
 
8
+ headers = {
9
+ 'Content-Type': 'application/json',
10
+ 'x-functions-key': api_key # Si está utilizando una clave de API
11
+ }
12
 
13
+ payload = {
14
+ 'operation': operation,
15
+ 'data': data
16
+ }
17
+
18
+ response = requests.post(function_url, json=payload, headers=headers)
19
+
20
+ if response.status_code == 200:
21
+ return response.json()
22
+ else:
23
+ raise Exception(f"Error calling Azure Function: {response.text}")