Commit 4d3a5a32 authored by Luis Acosta's avatar Luis Acosta

Version 1.0

parent bc591291
import requests import requests
import json
class Callcenter: class Callcenter:
def __init__(self,api_key,url): def __init__(self,api_key,url):
self.url=url self.url=url
...@@ -29,6 +29,7 @@ class Callcenter: ...@@ -29,6 +29,7 @@ class Callcenter:
} }
response = requests.get(url_center, headers=headers, verify=False) response = requests.get(url_center, headers=headers, verify=False)
return response return response
def insert_number_campaing(self,id_campaign,campaign_fields,campaign_data): def insert_number_campaing(self,id_campaign,campaign_fields,campaign_data):
url_center = f"{self.url}/api/outgoingcampaigns/{id_campaign}/add-calls" url_center = f"{self.url}/api/outgoingcampaigns/{id_campaign}/add-calls"
headers = { headers = {
...@@ -41,5 +42,47 @@ class Callcenter: ...@@ -41,5 +42,47 @@ class Callcenter:
"fields": campaign_fields, "fields": campaign_fields,
"data": campaign_data "data": campaign_data
} }
response = requests.post(url_center, headers=headers, json=payload, verify=False) response = requests.post(url_center, headers=headers, json=payload, verify=False)
return response.content return response.content
\ No newline at end of file
def created_campaing(self,camp_name,date_ini_camp,time_ini_camp,date_fin_camp,time_fin_camp,campaign_queue,camp_obsv):
url_center = f"{self.url}/api/outgoingcampaigns/"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"CCAuthorization": f"Bearer {self.token}",
"Cookie": self.cookie
}
payload = {
"name": camp_name,
"datetime_init": date_ini_camp,
"datetime_end": date_fin_camp,
"daytime_init": time_ini_camp,
"daytime_end": time_fin_camp,
"retries": "1",
"context": "from-internal",
"queue": campaign_queue,
"max_channels": "23",
"script": camp_obsv + ' <style type=\"text/css\">\r\nbody {\r\n\tbackground: #FFF;\r\n}\r\n</style>',
"forms": [
"5"
]
}
response = requests.post(url_center, headers=headers, json=payload, verify=False)
return response
def consult_campaing(self,campaign_id,campaign_date_in,campaign_date_out):
#url_center = f"{self.url}/api/outgoingcampaigns/"
#url_center_aditional = url_center + f"{campaign_id}/general-metrics?page=1&search&date_from='{campaign_date_in}'&date_to='{campaign_date_out}'&maxPerPage=100"
url_center_aditional = "https://mxcc-gruposerviandina.hiperpbx.com/api/outgoingcampaigns/90/general-metrics?page=1&search&date_from=2024-12-23&date_to=2024-12-23&maxPerPage=1000"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"CCAuthorization": f"Bearer {self.token}",
"Cookie": self.cookie
}
response = requests.get(url_center_aditional, headers=headers, verify=False)
return response.content
...@@ -158,31 +158,54 @@ def Generate_Campaign(): ...@@ -158,31 +158,54 @@ def Generate_Campaign():
#Update de registros en la campaña #Update de registros en la campaña
actualizar_campaign = db_cc.actualizar("update campaign set datetime_init = %s, datetime_end = %s, daytime_init = %s, daytime_end = %s, estatus = %s where id = %s ",(f'{str(date_ini_camp)}',f'{str(date_fin_camp)}',f'{str(time_ini_camp)}',f'{str(time_fin_camp)}',f'{camp_status}',f'{camp_id_search}')) actualizar_campaign = db_cc.actualizar("update campaign set datetime_init = %s, datetime_end = %s, daytime_init = %s, daytime_end = %s, estatus = %s where id = %s ",(f'{str(date_ini_camp)}',f'{str(date_fin_camp)}',f'{str(time_ini_camp)}',f'{str(time_fin_camp)}',f'{camp_status}',f'{camp_id_search}'))
#Conectar al CC2 para insertar datos en la la campaña #Conectar al CC2 para insertar datos en la la campaña
payload = {
"fields": campaign_fields,
"data": campaign_data
}
print(payload)
callcenter = Callcenter(api_key, cc_url) callcenter = Callcenter(api_key, cc_url)
id_campaign= 87 #id_campaign= 87 #Modificar por el valor ingresado
response = callcenter.search_campaing(id_campaign) response = callcenter.search_campaing(camp_id_search)
data = response.json()['id'] data = response.json()['id']
print(data)
insert=callcenter.insert_number_campaing(data,campaign_fields,campaign_data) insert=callcenter.insert_number_campaing(data,campaign_fields,campaign_data)
print(insert) print(insert)
data_response = json.loads(insert)["status"]
db_cc.cerrar() db_cc.cerrar()
#return jsonify({{payload}}), 200 #return jsonify({{payload}}), 200
return jsonify({"mensaje": f"Camp Ingreso Datos: {camp_data_input} Camp Resultado: {camp_data_search} Comparacion: {result} Resgistros: {payload}"}), 200 #return jsonify({"mensaje": f"Camp Ingreso Datos: {camp_data_input} Camp Resultado: {camp_data_search} Comparacion: {result} Resgistros: {payload}"}), 200
#return jsonify({"mensaje": f"Encontrado Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Fecha Comienzo: {camp_datetime_init_search} Hora Comienzo: {camp_daytime_init_search} Fecha Fin: {camp_datetime_end_search} Hora Fin: {camp_daytime_end_search} Queue: {camp_queue_search} ! Validar Registros de Ingreso"}), 200 return jsonify({"mensaje": f"Encontrado Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Fecha Comienzo: {camp_datetime_init_search} Hora Comienzo: {camp_daytime_init_search} Fecha Fin: {camp_datetime_end_search} Hora Fin: {camp_daytime_end_search} Queue: {camp_queue_search} Responce: {data_response}! Validar Registros de Ingreso"}), 200
else: else:
callcenter = Callcenter(api_key, cc_url)
cread_camp=callcenter.created_campaing(camp_name,date_ini_camp,time_ini_camp,date_fin_camp,time_fin_camp,campaign_queue,camp_obsv)
print(cread_camp)
return jsonify({"mensaje": f"No Encontrado Campaing , {camp_name}! Se debe crear una campaña"}), 401 return jsonify({"mensaje": f"No Encontrado Campaing , {camp_name}! Se debe crear una campaña"}), 401
@app.route('/Consult_Campaign', methods=['GET'])
@jwt_required()
def Consult_Campaign():
usuario = get_jwt_identity()
db = MySQLDatabase(host=db_host, user=db_user, password="", database=db_name_hiper_service)
nuevo_id = db.insertar("INSERT INTO hiper_service_accesos (usuario, token ,fecha_hora, status, message) VALUES (%s, %s, %s, %s, %s)",(f'{usuario}','',f'{fecha_hora}','Consult Campaing','Access'))
db.cerrar()
request_data = request.get_json()
dataCollection=request_data["dataCollection"]
campaign_id=request_data["id_campaign"]
campaign_date_ini=request_data["date_in"]
campaign_date_fin=request_data["date_out"]
#Buscar Campaña
callcenter = Callcenter(api_key, cc_url)
consult_calls=callcenter.consult_campaing(campaign_id,campaign_date_ini,campaign_date_fin)
data_response = json.loads(consult_calls)["hydra:member"]
print(data_response)
raw_json = data_response[0]
#return jsonify({"mensaje": f"Datos Ingresados , {dataCollection} ;{campaign_id};{campaign_date_ini};{campaign_date_fin}"}), 401
return jsonify(f"{raw_json}", 200)
@jwt.expired_token_loader @jwt.expired_token_loader
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment