Commit 3d1b81d2 authored by Luis Acosta's avatar Luis Acosta

se adiciona camp agente

parent 27792f80
...@@ -20,7 +20,7 @@ class Callcenter: ...@@ -20,7 +20,7 @@ class Callcenter:
def search_campaing(self,id_campaign): def search_campaing(self,id_campaign):
url_center = f"{self.url}/api/outgoingcampaigns/{id_campaign}" url_center = f"{self.url}/api/outgoingcampaigns/{id_campaign}"
print(f"url: {url_center}") #print(f"url: {url_center}")
headers = { headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Accept": "application/json", "Accept": "application/json",
...@@ -43,6 +43,7 @@ class Callcenter: ...@@ -43,6 +43,7 @@ class Callcenter:
"data": campaign_data "data": campaign_data
} }
#return url_center,headers,payload
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
......
...@@ -9,23 +9,15 @@ from flask import Flask, request, jsonify, render_template, redirect, url_for, s ...@@ -9,23 +9,15 @@ from flask import Flask, request, jsonify, render_template, redirect, url_for, s
from Connect_Db import MySQLDatabase from Connect_Db import MySQLDatabase
from flask_jwt_extended import JWTManager, create_access_token, create_refresh_token, jwt_required, get_jwt_identity from flask_jwt_extended import JWTManager, create_access_token, create_refresh_token, jwt_required, get_jwt_identity
db_host = os.getenv("DB_HOST") db_host = os.getenv("DB_HOST")
db_user = os.getenv("DB_USER") db_user = os.getenv("DB_USER")
db_pass = os.getenv("DB_PASS") db_pass = os.getenv("DB_PASS")
db_call_center = os.getenv("DB_NAME_CALL_CENTER") db_call_center = os.getenv("DB_NAME_CALL_CENTER")
#db_name_asterisk = os.getenv("DB_NAME_ASTERISK")
#db_name_cdr = os.getenv("DB_NAME_CDR")
db_name_hiper_service = os.getenv("DB_NAME_HIPER_SERVICE") db_name_hiper_service = os.getenv("DB_NAME_HIPER_SERVICE")
#cc_url = 'https://mxcc-gruposerviandina.hiperpbx.com'
#cc_url = 'https://mxcc-serviandina-marcimex.hiperpbx.com'
#api_key = '07j3FHMnDNrIV43A2eB8BlNEDEf1FVXQQtDuNm82jaPANIetnYTiL97QzenOdlbGKEqyd8rtD0HQWtaQ'
cc_url = os.getenv("URL_CC") cc_url = os.getenv("URL_CC")
api_key = os.getenv("API_KEY_CC") api_key = os.getenv("API_KEY_CC")
user_center_id = os.getenv("CENTER_ID_CC") user_center_id = os.getenv("CENTER_ID_CC")
print(timedelta(minutes=int(os.getenv("JWT_ACCESS_TOKEN_EXPIRES",5))))
hm_url ='https://mxme.hiperpbx.com' hm_url ='https://mxme.hiperpbx.com'
hm_api_key ='c4ce8a7f84c01674d573d4df5cf2e410' hm_api_key ='c4ce8a7f84c01674d573d4df5cf2e410'
hm_email ='serviceaccount@serviandina.com' hm_email ='serviceaccount@serviandina.com'
...@@ -80,7 +72,8 @@ def Generate_Campaign(): ...@@ -80,7 +72,8 @@ def Generate_Campaign():
campaign_observ=request_data["campaign_observ"] campaign_observ=request_data["campaign_observ"]
campaign_fields=request_data["fields"] campaign_fields=request_data["fields"]
campaign_data=request_data["data"] campaign_data=request_data["data"]
#Validar campos de fecha y hora y diferencias de tiempos entre ambas campaign_date_ini=campaign_date_ini + ' 06:00:00'
campaign_date_fin=campaign_date_fin + ' 21:00:00'
date_ini_check = convertir_fecha_hora(campaign_date_ini) date_ini_check = convertir_fecha_hora(campaign_date_ini)
date_ini_result = date_ini_check[0] date_ini_result = date_ini_check[0]
date_ini_camp = date_ini_check[1] date_ini_camp = date_ini_check[1]
...@@ -125,9 +118,7 @@ def Generate_Campaign(): ...@@ -125,9 +118,7 @@ def Generate_Campaign():
check_field_cant = check_fields[1] check_field_cant = check_fields[1]
check_field_data = check_fields[2] check_field_data = check_fields[2]
else: else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Fileds"}), 401 return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Fields"}), 401
#check_data=valid_array_data(campaign_data,check_field_cant)
#Modificacion debido que primer campo debe ser numerico
check_data=True check_data=True
if(check_data==True): if(check_data==True):
return_data='ok' return_data='ok'
...@@ -157,30 +148,25 @@ def Generate_Campaign(): ...@@ -157,30 +148,25 @@ def Generate_Campaign():
result='Datos Distintos' result='Datos Distintos'
#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
#Modo local sacar luego a implementacion
callcenter = Callcenter(api_key, cc_url, user_center_id) callcenter = Callcenter(api_key, cc_url, user_center_id)
#id_campaign= 87 #Modificar por el valor ingresado
response = callcenter.search_campaing(camp_id_search) response = callcenter.search_campaing(camp_id_search)
data = response.json()['id'] data = response.json()['id']
insert=callcenter.insert_number_campaing(data,campaign_fields,campaign_data) insert=callcenter.insert_number_campaing(data,campaign_fields,campaign_data)
#print(insert)
data_response = json.loads(insert)["status"] data_response = json.loads(insert)["status"]
db_cc.cerrar() db_cc.cerrar()
#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"Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Registros Ingresados"}), 200 return jsonify({"mensaje": f"Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Registros Ingresados"}), 200
else: else:
#Modo local sacar luego a implementacion
callcenter = Callcenter(api_key, cc_url, user_center_id) callcenter = Callcenter(api_key, cc_url, user_center_id)
cread_camp=callcenter.created_campaing(camp_name,date_ini_camp,time_ini_camp,date_fin_camp,time_fin_camp,campaign_queue,camp_obsv) 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)
id_camp =json.loads(cread_camp)["id"] id_camp =json.loads(cread_camp)["id"]
insert=callcenter.insert_number_campaing(id_camp,campaign_fields,campaign_data) insert=callcenter.insert_number_campaing(id_camp,campaign_fields,campaign_data)
data_response = json.loads(insert)["status"] data_response = json.loads(insert)["status"]
return jsonify({"mensaje": f"Campaing ,ID: {id_camp} Name: {camp_name} Registros Ingresados"}), 200 return jsonify({"mensaje": f"Campaing ,ID: {id_camp} Name: {camp_name} Registros Ingresados"}), 200
#return jsonify({"mensaje": f"Campaing , {camp_name}! Id {id_camp}"}), 200
@app.route('/Generate_Campaign_Agent', methods=['GET']) @app.route('/Generate_Campaign_Agent', methods=['GET'])
@jwt_required() @jwt_required()
...@@ -201,6 +187,8 @@ def Generate_Campaign_Agent(): ...@@ -201,6 +187,8 @@ def Generate_Campaign_Agent():
campaign_fields=request_data["fields"] campaign_fields=request_data["fields"]
campaign_data=request_data["data"] campaign_data=request_data["data"]
#Validar campos de fecha y hora y diferencias de tiempos entre ambas #Validar campos de fecha y hora y diferencias de tiempos entre ambas
campaign_date_ini=campaign_date_ini + ' 06:00:00'
campaign_date_fin=campaign_date_fin + ' 21:00:00'
date_ini_check = convertir_fecha_hora(campaign_date_ini) date_ini_check = convertir_fecha_hora(campaign_date_ini)
date_ini_result = date_ini_check[0] date_ini_result = date_ini_check[0]
date_ini_camp = date_ini_check[1] date_ini_camp = date_ini_check[1]
...@@ -208,10 +196,93 @@ def Generate_Campaign_Agent(): ...@@ -208,10 +196,93 @@ def Generate_Campaign_Agent():
date_fin_check = convertir_fecha_hora(campaign_date_fin) date_fin_check = convertir_fecha_hora(campaign_date_fin)
date_fin_result = date_fin_check[0] date_fin_result = date_fin_check[0]
date_fin_camp = date_fin_check[1] date_fin_camp = date_fin_check[1]
time_fin_camp = date_fin_check[2] time_fin_camp = date_fin_check[2]
return_agent=find_name_position(campaign_agent) if (date_ini_result==True & date_fin_result==True):
return jsonify({"mensaje": f"Campaing , {campaign_name}! Name Agent {campaign_agent} Agente Valido: {return_agent}"}), 200 #Chequear diferencias de Tiempos entre ambas fechas y horas
date_in=str(date_ini_camp) + ' ' + str(time_ini_camp)
date_out=str(date_fin_camp) + ' ' + str(time_fin_camp)
check_date = check_date_in_out(date_in,date_out)
if(check_date==False):
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Fecha Inicial debe ser menor a Fecha Final"}), 401
else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Fecha"}), 401
valid_status_camp=status_camp(campaign_status)
valid_status_camp_result=valid_status_camp[0]
if (valid_status_camp_result==True):
camp_status=valid_status_camp[1]
else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Status Invalido de Campaña"}), 401
check_name_obsv=limpiar_texto(campaign_observ)
check_name_obsv_result=check_name_obsv[0]
if(check_name_obsv_result==True):
camp_obsv=check_name_obsv[1]
else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Observaciones"}), 401
#Validar Campo Fields campo 0 =phone resto string
check_fields=valid_array_fields(campaign_fields)
if(check_fields[0]==True):
check_field_cant = check_fields[1]
check_field_data = check_fields[2]
else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Fileds"}), 401
#Validaciones segun ingreso de Name de Agente (campaign_agent)
return_agent=find_name_position(campaign_agent)
if not return_agent:
#Agente invalido No continuar con la operatoria
return jsonify({"mensaje": f"Campaing , {campaign_name}! Name Agent {campaign_agent} Agente Invalido: {return_agent}"}), 422
#Agente valido Continuar con la operatoria
check_name_camp=limpiar_texto(campaign_name)
check_name_camp_result=check_name_camp[0]
if(check_name_camp_result==True):
camp_name=check_name_camp[1]
else:
return jsonify({"mensaje": f"Error al generar Campaing , {campaign_name}! Formato Invalido Nombre de Campaña"}), 401
#Buscar nombre de camapaña realcionada con el agente
camp='CampAgent' + return_agent
db_cc = MySQLDatabase(host=db_host, user=db_user, password=db_pass, database=db_call_center)
resultado_campaign = db_cc.consultar("SELECT * FROM campaign WHERE name = %s limit 1",(f'{camp}',))
if resultado_campaign:
for registro in resultado_campaign:
camp_id_search=registro['id']
camp_name_search=registro['name']
camp_status_search=registro['estatus']
camp_datetime_init_search=registro['datetime_init']
camp_datetime_end_search=registro['datetime_end']
camp_daytime_init_search=str(registro['daytime_init'])
camp_daytime_end_search=str(registro['daytime_end'])
camp_queue_search=registro['queue']
time_ini = convertir_hora(camp_daytime_init_search)
time_out = convertir_hora(camp_daytime_end_search)
camp_data_search=[camp_status_search,str(camp_datetime_init_search),str(camp_datetime_end_search),time_ini,time_out]
camp_data_input=[camp_status,str(date_ini_camp),str(date_fin_camp),str(time_ini_camp),str(time_fin_camp)]
if (camp_data_search==camp_data_input):
result="Datos Iguales"
#No realiza ninguna accion
else:
result='Datos Distintos'
camp_html_obsv=camp_obsv + ' <style type="text/css"> body { background: #FFF; } </style> <style type="text/css"> body { background: #FFF; } </style> <style type="text/css"> body { background: #FFF; } </style> <style type="text/css"> body { background: #FFF; } </style>'
print(camp_html_obsv)
#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, script =%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_html_obsv}',f'{camp_id_search}'))
#Conectar al CC2 para insertar datos en la la campaña
#Sacar luego de la implementacion
callcenter = Callcenter(api_key, cc_url, user_center_id)
response = callcenter.search_campaing(camp_id_search)
data = response.json()['id']
insert=callcenter.insert_number_campaing(data,campaign_fields,campaign_data)
data_response = json.loads(insert)["status"]
db_cc.cerrar()
#return jsonify({"mensaje": f"Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Registros Ingresados: {data_response}"})
return jsonify({"mensaje": f"Campaing ,ID: {camp_id_search} Name: {camp_name_search} Status: {camp_status_search} Registros Ingresados: OK"})
else:
return jsonify({"mensaje": f"Campaing Search Error: , {camp}! Name Agent {campaign_agent} Agente Valido: {return_agent}"}), 404
@app.route('/Consult_Campaign', methods=['GET']) @app.route('/Consult_Campaign', methods=['GET'])
@jwt_required() @jwt_required()
def Consult_Campaign(): def Consult_Campaign():
......
...@@ -121,67 +121,78 @@ def validate_keys(data): ...@@ -121,67 +121,78 @@ def validate_keys(data):
def find_name_position(name): def find_name_position(name):
dictionary = { dictionary = {
"2017" : "Paucar Tapia Dennis Andres", "2052":"EARAUJO",
"2018" : "Hurtado Tocache Mayra Biviana", "2051":"GAREVALO",
"2019" : "Bermeo Cajamarca Tania Marcela ", "2070":"JPBACULIMA",
"2020" : "Sojos Bermeo Lourdes Maricela", "2026":"ABARBECHO",
"2021" : "Robles Guerra Jhoanna Maricela", "2019":"TMBERMEO",
"2022" : "Ortega Leon Maria Daniela", "2071":"DABERMEO",
"2023" : "Peralta Jaramillo Michelle Catalina", "2025":"WBRAVO",
"2024" : "Zambrano Santiak Maria Dolores ", "2053":"AECABRERA",
"2025" : "Bravo Andrade Willy Luis", "2054":"JCAGUANA",
"2026" : "Barbecho Arias Alba Janneth", "2027":"ECALDERON",
"2027" : "Calderon Sucuzhanay Eliza Katherine", "2072":"GCARCHI",
"2028" : "Jara Caceres Virginia Carolina", "2033":"MCARDENAS",
"2030" : "Sanchez Zhagnay Angel Marcelo", "2047":"CALOPEZ",
"2031" : "Gomez Ochoa Cristian Gabriel", "2045":"CCHANG",
"2032" : "Leon Duenas Valeria Estefania ", "2055":"PFCRESPO",
"2033" : "Cardenas Torres Madelyne Coraima", "2057":"MESPANA",
"2034" : "Samaniego Gonzaga Camila Nicole ", "2056":"PESPARZA",
"2035" : "Suarez Bacuilima Andres Santiago", "2040":"JFAICAN",
"2037" : "Tapia Penaloza Andreina De Los Angeles", "2038":"CNFLORES",
"2038" : "Flores Lopez Christian Nicolas ", "2044":"GEOCHOA",
"2040" : "Faican Vasquez Jennifer Eliana", "2031":"CGGOMEZ",
"2041" : "Villa Torres Joseline Andrea ", "2018":"MHURTADO",
"2042" : "Penafiel Rodas Karen Salome ", "2028":"VJARA",
"2043" : "Jaramillo Gonzaga Evelin Lizbeth ", "2043":"EJARAMILLO",
"2044" : "Gabriela Elizabeth Ochoa Fajardo", "2073":"ALATA",
"2045" : "Christopher Brian Chang Tapia", "2032":"VLEON",
"2046" : "Maria Guadalupe Arias Asmal", "2074":"JMAITA",
"2047" : "Christian Adrian Lopez Durazno", "2046":"MGARIAS",
"2050" : "Matute Segarra Miriam Viviana ", "2050":"MMATUTE",
"2051" : "Arevalo Jara Gabriela Alexandra", "2075":"GMEJIA",
"2052" : "Araujo Segovia Erika Patricia", "2058":"AMENDOZA",
"2053" : "Cabrera Arteaga Andreina Estefania", "2076":"MMORALES",
"2054" : "Caguana Laime Jhoanna Maribel", "2077":"ALMURILLO",
"2055" : "Crespo Pizarro Paola Fernanda", "2059":"PNAULA",
"2056" : "Esparza Ayala Pablo Andres", "2060":"RENIETO",
"2057" : "Espana Marcia", "2061":"XORDONEZ",
"2058" : "Mendoza Avila Andres Fabricio", "2022":"MDORTEGA",
"2059" : "Naula Cardenas Paola Cecibel", "2062":"aparra",
"2060" : "Nieto Guerrero Rolando Estuardo", "2017":"DPAUCAR",
"2061" : "Ordonez Plaza Arturo Xavier", "2042":"KPENAFIEL",
"2062" : "Parra Reyes Andres Remigio", "2023":"MCPERALTAJ",
"2063" : "Ramon Rodas Katherine Fernanda", "2063":"KRAMON",
"2064" : "Rodriguez Rodriguez Paul Esteban", "2021":"JROBLES",
"2065" : "Romero Calero Stefania Magdalena", "2064":"PRODRIGUEZ",
"2066" : "Tenezaca Maza Adriana Nube", "2065":"SROMERO",
"2067" : "Uzhca Gonzalez Jessica Karina", "2078":"JJROMERO",
"2068" : "Velez Arcentales Jenny Isabel", "2034":"CSAMANIEGO",
"2069" : "Yanez Arevalo Maria Belen", "2030":"ASANCHEZ",
"2070" : "Baculima Bueno Jessica Priscila", "2020":"LSOJOS",
"2071" : "Bermeo Zuna Diego Alejandro", "2035":"ASSUAREZ",
"2072" : "Carchi Ordonez Gabriela Elizabeth", "2037":"ATAPIA",
"2073" : "Lata Sinchi Ana Lucia", "2066":"ATENEZACA",
"2074" : "Maita Robles John Christian", "2079":"HULLOA",
"2075" : "Mejia Lojano Gloria Beatriz", "2067":"JUZHCA",
"2076" : "Morales Figueroa Miriam Susana", "2080":"DVALDIVIESO",
"2077" : "Murillo Pinos Ana Lucia", "2081":"TVASQUEZ",
"2078" : "Romero Carpio Joseline Lorena", "2068":"IVELEZ",
"2079" : "Ulloa Vintimilla Hernan Marcelo", "2041":"JAVILLA",
"2080" : "Valdivieso Aviles Jessica Daniela", "2082":"SVIVAR",
"2081" : "Vasquez Sari Tatiana Cecibel", "2069":"MBYANEZ",
"2082" : "Vivar Rivadeneira Susana Elizabeth" "2024":"MDZAMBRANO",
"2096":"GAANDRADE",
"2097":"S/N",
"2098":"ECARDENAS",
"2099":"BBENAVIDES",
"2100":"KPAUZHI",
"2101":"AGUANUCHI",
"2102":"PCARPIO",
"2103":"MBOCHOA",
"2104":"CCANDO",
"2095":"BPLOPEZ",
"4050":"Test Indurama"
} }
for key, value in dictionary.items(): for key, value in dictionary.items():
if value == name: if value == name:
......
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