added extra query
This commit is contained in:
+45
-45
@@ -1,45 +1,45 @@
|
||||
from app.config import settings
|
||||
import requests
|
||||
from app.utils.logger import logger
|
||||
|
||||
def get_headers():
|
||||
BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL
|
||||
BANK_CALL_AUTH_ENDPOINT = settings.BANK_CALL_AUTH_ENDPOINT
|
||||
BANK_CALL_BASIC_AUTH_USERNAME = settings.BANK_CALL_BASIC_AUTH_USERNAME
|
||||
BANK_CALL_BASIC_AUTH_PASSWORD = settings.BANK_CALL_BASIC_AUTH_PASSWORD
|
||||
BANK_GRANT_TYPE = settings.BANK_GRANT_TYPE
|
||||
#authenticate
|
||||
url = f"{BANK_CALL_BASE_URL}{BANK_CALL_AUTH_ENDPOINT}"
|
||||
data = {
|
||||
"grant_type": BANK_GRANT_TYPE,
|
||||
"username": BANK_CALL_BASIC_AUTH_USERNAME,
|
||||
"password": "G7$k9@pL2!qR"
|
||||
}
|
||||
logger.info(f"Calling Bank Call-Auth Endpoint: {url}")
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=data, headers=headers, timeout=10)
|
||||
response.raise_for_status() # Raises HTTPError for 4xx/5xx
|
||||
result = response.json()
|
||||
|
||||
|
||||
# Check if access_token is present
|
||||
if 'access_token' not in result:
|
||||
logger.error("No access_token found in Bank Call Auth response")
|
||||
return {"error": "Authentication failed: no access_token returned"}
|
||||
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": settings.BANK_CALL_API_KEY,
|
||||
"App-Id": settings.BANK_CALL_APP_ID,
|
||||
"Authorization": f"Bearer {result['access_token']}"
|
||||
}
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Failed to get auth token: {e}")
|
||||
raise
|
||||
except ValueError as e:
|
||||
logger.error(f"Failed to parse auth response JSON: {e}")
|
||||
raise
|
||||
from app.config import settings
|
||||
import requests
|
||||
from app.utils.logger import logger
|
||||
|
||||
def get_headers():
|
||||
BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL
|
||||
BANK_CALL_AUTH_ENDPOINT = settings.BANK_CALL_AUTH_ENDPOINT
|
||||
BANK_CALL_BASIC_AUTH_USERNAME = settings.BANK_CALL_BASIC_AUTH_USERNAME
|
||||
BANK_CALL_BASIC_AUTH_PASSWORD = settings.BANK_CALL_BASIC_AUTH_PASSWORD
|
||||
BANK_GRANT_TYPE = settings.BANK_GRANT_TYPE
|
||||
#authenticate
|
||||
url = f"{BANK_CALL_BASE_URL}{BANK_CALL_AUTH_ENDPOINT}"
|
||||
data = {
|
||||
"grant_type": BANK_GRANT_TYPE,
|
||||
"username": BANK_CALL_BASIC_AUTH_USERNAME,
|
||||
"password": "G7$k9@pL2!qR"
|
||||
}
|
||||
logger.info(f"Calling Bank Call-Auth Endpoint: {url}")
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=data, headers=headers, timeout=10)
|
||||
response.raise_for_status() # Raises HTTPError for 4xx/5xx
|
||||
result = response.json()
|
||||
|
||||
|
||||
# Check if access_token is present
|
||||
if 'access_token' not in result:
|
||||
logger.error("No access_token found in Bank Call Auth response")
|
||||
return {"error": "Authentication failed: no access_token returned"}
|
||||
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": settings.BANK_CALL_API_KEY,
|
||||
"App-Id": settings.BANK_CALL_APP_ID,
|
||||
"Authorization": f"Bearer {result['access_token']}"
|
||||
}
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Failed to get auth token: {e}")
|
||||
raise
|
||||
except ValueError as e:
|
||||
logger.error(f"Failed to parse auth response JSON: {e}")
|
||||
raise
|
||||
|
||||
+15
-15
@@ -1,16 +1,16 @@
|
||||
def preprocess_loan_charges_data(data):
|
||||
"""
|
||||
Preprocesses the data into a dictionary for efficient lookups by 'code'.
|
||||
|
||||
Args:
|
||||
data: A list of dictionaries.
|
||||
|
||||
Returns:
|
||||
A dictionary where keys are 'code' values and values are the corresponding dictionaries from the input data.
|
||||
If multiple items have the same code, the last one encountered will be stored.
|
||||
"""
|
||||
preprocessed = {}
|
||||
for item in data:
|
||||
if 'code' in item:
|
||||
preprocessed[item['code']] = item
|
||||
def preprocess_loan_charges_data(data):
|
||||
"""
|
||||
Preprocesses the data into a dictionary for efficient lookups by 'code'.
|
||||
|
||||
Args:
|
||||
data: A list of dictionaries.
|
||||
|
||||
Returns:
|
||||
A dictionary where keys are 'code' values and values are the corresponding dictionaries from the input data.
|
||||
If multiple items have the same code, the last one encountered will be stored.
|
||||
"""
|
||||
preprocessed = {}
|
||||
for item in data:
|
||||
if 'code' in item:
|
||||
preprocessed[item['code']] = item
|
||||
return preprocessed
|
||||
+13
-13
@@ -1,13 +1,13 @@
|
||||
import logging
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
# logging.StreamHandler(), # Log to console
|
||||
logging.FileHandler("app.log", mode='a') # Log to file
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger("DetectionService")
|
||||
import logging
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s - %(levelname)s - %(message)s",
|
||||
handlers=[
|
||||
# logging.StreamHandler(), # Log to console
|
||||
logging.FileHandler("app.log", mode='a') # Log to file
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger("DetectionService")
|
||||
|
||||
+39
-39
@@ -1,40 +1,40 @@
|
||||
from flask_mail import Message
|
||||
from flask import current_app
|
||||
from app.extensions import mail
|
||||
import pandas as pd
|
||||
from io import BytesIO
|
||||
|
||||
def get_report_data():
|
||||
"""
|
||||
Fetch and return loan summary data.
|
||||
"""
|
||||
return [
|
||||
{"Type": "Disbursement", "Count": 45},
|
||||
{"Type": "Repayment", "Count": 32},
|
||||
]
|
||||
def send_report_email(report_data: list, recipients: list):
|
||||
"""
|
||||
Sends an HTML + Excel report to the given email recipients.
|
||||
"""
|
||||
df = pd.DataFrame(report_data)
|
||||
output = BytesIO()
|
||||
df.to_excel(output, index=False)
|
||||
output.seek(0)
|
||||
|
||||
html_table = df.to_html(index=False, border=1)
|
||||
|
||||
msg = Message(
|
||||
subject="Loan Report Summary",
|
||||
recipients=recipients,
|
||||
html=f"<h3>Loan Report Summary</h3>{html_table}",
|
||||
)
|
||||
msg.attach(
|
||||
"loan_report.xlsx",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
output.read()
|
||||
)
|
||||
|
||||
with current_app.app_context():
|
||||
mail.send(msg)
|
||||
|
||||
from flask_mail import Message
|
||||
from flask import current_app
|
||||
from app.extensions import mail
|
||||
import pandas as pd
|
||||
from io import BytesIO
|
||||
|
||||
def get_report_data():
|
||||
"""
|
||||
Fetch and return loan summary data.
|
||||
"""
|
||||
return [
|
||||
{"Type": "Disbursement", "Count": 45},
|
||||
{"Type": "Repayment", "Count": 32},
|
||||
]
|
||||
def send_report_email(report_data: list, recipients: list):
|
||||
"""
|
||||
Sends an HTML + Excel report to the given email recipients.
|
||||
"""
|
||||
df = pd.DataFrame(report_data)
|
||||
output = BytesIO()
|
||||
df.to_excel(output, index=False)
|
||||
output.seek(0)
|
||||
|
||||
html_table = df.to_html(index=False, border=1)
|
||||
|
||||
msg = Message(
|
||||
subject="Loan Report Summary",
|
||||
recipients=recipients,
|
||||
html=f"<h3>Loan Report Summary</h3>{html_table}",
|
||||
)
|
||||
msg.attach(
|
||||
"loan_report.xlsx",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
output.read()
|
||||
)
|
||||
|
||||
with current_app.app_context():
|
||||
mail.send(msg)
|
||||
|
||||
return "Report email sent"
|
||||
Reference in New Issue
Block a user