Commit 648a3538 authored by Luis Acosta's avatar Luis Acosta

Version 1.0.4

parent 958f6572
import requests
import json
class HMConnect:
def __init__(self,api_key,email,url):
self.url=url
# Paso 1: Hacer un POST para obtener el token
requests.packages.urllib3.disable_warnings()
url_token = f"{self.url}/api/login_api_key"
payload = {"apikey": f"{api_key}","email" : f"{email}"}
response = requests.post(url_token, json=payload, verify=False)
self.token = response.json()['token']
#print(self.token)
def search_agent(self,mail_agent):
url_center = f"{self.url}/api/agents?user.email={mail_agent}"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": f"Bearer {self.token}"
}
response = requests.get(url_center, headers=headers, verify=False)
print(response.content)
\ No newline at end of file
import os
import json
from Connect_CC2 import Callcenter
from functions import convertir_fecha_hora,check_date_in_out,limpiar_texto,status_camp,valid_array_fields,valid_array_data,convertir_hora
from Connect_HM import HMConnect
from functions import convertir_fecha_hora,check_date_in_out,limpiar_texto,status_camp,valid_array_fields,valid_array_data,convertir_hora,validar_dict,validate_keys,find_name_position
from datetime import datetime, timedelta
from dotenv import load_dotenv
from flask import Flask, request, jsonify, render_template, redirect, url_for, session, flash
......@@ -16,11 +17,11 @@ db_call_center = os.getenv("DB_NAME_CALL_CENTER")
#db_name_cdr = os.getenv("DB_NAME_CDR")
db_name_hiper_service = os.getenv("DB_NAME_HIPER_SERVICE")
cc_url = 'https://mxcc-gruposerviandina.hiperpbx.com'
api_key = '07j3FHMnDNrIV43A2eB8BlNEDEf1FVXQQtDuNm82jaPANIetnYTiL97QzenOdlbGKEqyd8rtD0HQWtaQ'
cc_url = 'https://mxcc-gruposerviandina.hiperpbx.com'
api_key = '07j3FHMnDNrIV43A2eB8BlNEDEf1FVXQQtDuNm82jaPANIetnYTiL97QzenOdlbGKEqyd8rtD0HQWtaQ'
hm_url ='https://mxme.hiperpbx.com'
hm_api_key ='c4ce8a7f84c01674d573d4df5cf2e410'
hm_email ='serviceaccount@serviandina.com'
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = os.getenv("JWT_SECRET_KEY", "clave_por_defecto")
......@@ -30,14 +31,11 @@ app.config["JWT_TOKEN_LOCATION"] = os.getenv("JWT_TOKEN_LOCATION", "headers").sp
app.config["JWT_HEADER_NAME"] = os.getenv("JWT_HEADER_NAME", "Authorization")
app.config["JWT_HEADER_TYPE"] = os.getenv("JWT_HEADER_TYPE", "Bearer")
jwt = JWTManager(app)
USUARIOS = {"admin": "1234"}
fecha_hora = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
#formato_convertir_fecha = "%d/%m/%Y %H:%M:%S"
@app.route('/')
def home():
return jsonify({"error": "Error Access"}), 401
#return jsonify(resultado)
@app.route('/login', methods=['POST'])
def login():
......@@ -176,8 +174,37 @@ def Generate_Campaign():
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 , {camp_name}! Id {id_camp}"}), 200
@app.route('/Generate_Campaign_Agent', methods=['GET'])
@jwt_required()
def Generate_Campaign_Agent():
usuario = get_jwt_identity()
db = MySQLDatabase(host=db_host, user=db_user, password=db_pass, 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}','Generate Campaing Agent','Access'))
db.cerrar()
request_data = request.get_json()
dataCollection=request_data["dataCollection"]
campaign_id=request_data["campaign_id"]
campaign_name=request_data["campaign_name"]
campaign_date_ini=request_data["campaign_date_ini"]
campaign_date_fin=request_data["campaign_date_fin"]
campaign_agent=request_data["campaign_agent"]
campaign_status=request_data["campaign_status"]
campaign_observ=request_data["campaign_observ"]
campaign_fields=request_data["fields"]
campaign_data=request_data["data"]
#Validar campos de fecha y hora y diferencias de tiempos entre ambas
date_ini_check = convertir_fecha_hora(campaign_date_ini)
date_ini_result = date_ini_check[0]
date_ini_camp = date_ini_check[1]
time_ini_camp = date_ini_check[2]
date_fin_check = convertir_fecha_hora(campaign_date_fin)
date_fin_result = date_fin_check[0]
date_fin_camp = date_fin_check[1]
time_fin_camp = date_fin_check[2]
return_agent=find_name_position(campaign_agent)
return jsonify({"mensaje": f"Campaing , {campaign_name}! Name Agent {campaign_agent} Agente Valido: {return_agent}"}), 200
@app.route('/Consult_Campaign', methods=['GET'])
@jwt_required()
def Consult_Campaign():
......@@ -198,15 +225,6 @@ def Consult_Campaign():
resp = jsonify(message)
resp.status_code = 200
return resp
#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({"response":f"{data_response}"}),200
@jwt.expired_token_loader
def token_caducado(header, payload):
......@@ -229,44 +247,5 @@ def token_no_fresco():
"error": "Se requiere un token fresco para esta operación."
}), 401
@app.route('/prueba', methods=['POST'])
def acceso():
headers = request.headers
auth = headers.get("Authorization")
if auth == 'Bearer cGJ4OnMzWFRnM0hTQ1Y1R':
request_data = request.get_json()
if 'dataCollection' in request_data:
data_collection = request_data['dataCollection']
return jsonify({"message": "DataCollection: data_collection"}), 200
else:
return jsonify({"message": "DataCollection: Not Found"}), 401
else:
return jsonify({"message": "ERROR: Unauthorized"}), 401
# if auth == 'Bearer cGJ4OnMzWFRnM0hTQ1Y1R':
# request_data = request.get_json()
# if 'dataCollection' in request_data:
# data_collection = request_data['dataCollection']
#
# if (data_collection=='crm_insert_campaing'):
# id_campaign = request_data['id_campaign']
# fields = request_data['fields']
# data = request_data['data']
# #return jsonify({"message": "OK: Authorized"}), 200
# return jsonify({"message": "OK: data_collection"}), 200
# else:
# return 'Invalid Data Coellections'
# else:
# return jsonify({"message": "ERROR: Unauthorized"}), 401
#return auth
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
......@@ -111,4 +111,124 @@ def valid_array_data(array_in,count):
result=False
else:
result=False
return result
\ No newline at end of file
return result
def validar_dict(dictionary):
return not bool(dictionary)
def validate_keys(data):
return isinstance(data, dict)
def find_name_position(name):
dictionary = {
"2000": "Benenaula Choco Margoth Elizabeth",
"2001": "Campoverde Samaniego Bryan Andres",
"2002": "Contreras Guillermo Laura Fernanda",
"2003": "Cuenca Sanchez Carmen Maria",
"2004": "Granados Tomala Ileana Gabriela",
"2005": "Guissella Alejandrina Ortega Alvarez",
"2006": "Henry Esteban Urdiales Landy",
"2007": "Jaramillo Calle Josseline Cristina",
"2008": "Maza Guaman Rosa Salome",
"2009": "Jhon Byron Paula Calle",
"2010": "Rodriguez Pena Andrea Del Cisne",
"2011": "Santiago Sebastian Carpio Aviles",
"2012": "Vera Luzuriaga Viviana Carolina",
"2013": "Tapia Yunga Jaime Adrian",
"2014": "Godoy Zambrano Katiusca",
"2015": "Alexandra Estefania Villa Torres",
"2016": "Delgado Baque Gabriela Elizabeth",
"2017": "Paucar Tapia Dennis Andres",
"2018": "Hurtado Tocache Mayra Biviana",
"2019": "Bermeo Cajamarca Tania Marcela",
"2020": "Sojos Bermeo Lourdes Maricela",
"2021": "Robles Guerra Jhoanna Maricela",
"2022": "Ortega Leon Maria Daniela",
"2023": "Peralta Jaramillo Michelle Catalina",
"2024": "Zambrano Santiak Maria Dolores",
"2025": "Bravo Andrade Willy Luis",
"2026": "Barbecho Arias Alba Janneth",
"2027": "Calderon Sucuzhanay Eliza Katherine",
"2028": "Jara Caceres Virginia Carolina",
"2029": "Vintimilla Vasconez Maria Angelica",
"2030": "Sanchez Zhagnay Angel Marcelo",
"2031": "Gomez Ochoa Cristian Gabriel",
"2032": "Leon Duenas Valeria Estefania",
"2033": "Cardenas Torres Madelyne Coraima",
"2034": "Samaniego Gonzaga Camila Nicole",
"2035": "Suarez Bacuilima Andres Santiago",
"2036": "Marin Auquilla Rodrigo Fernando",
"2037": "Tapia Penaloza Andreina De Los Angeles",
"2038": "Flores Lopez Christian Nicolas",
"2039": "Sarmiento Verdugo Diana Patricia",
"2040": "Faican Vasquez Jennifer Eliana",
"2041": "Villa Torres Joseline Andrea",
"2042": "Penafiel Rodas Karen Salome",
"2043": "Jaramillo Gonzaga Evelin Lizbeth",
"2044": "Gabriela Elizabeth Ochoa Fajardo",
"2045": "Christopher Brian Chang Tapia",
"2046": "Maria Guadalupe Arias Asmal",
"2047": "Christian Adrian Lopez Durazno",
"2048": "Buncay Dutan Natalia Gabriela",
"2049": "Francisco Javier Arevalo Rosas",
"2050": "Matute Segarra Miriam Viviana",
"2051": "Arevalo Jara Gabriela Alexandra",
"2052": "Araujo Segovia Erika Patricia",
"2053": "Cabrera Arteaga Andreina Estefania",
"2054": "Caguana Laime Jhoanna Maribel",
"2055": "Crespo Pizarro Paola Fernanda",
"2056": "Esparza Ayala Pablo Andres",
"2057": "Espana Marcia",
"2058": "Mendoza Avila Andres Fabricio",
"2059": "Naula Cardenas Paola Cecibel",
"2060": "Nieto Guerrero Rolando Estuardo",
"2061": "Ordonez Plaza Arturo Xavier",
"2062": "Parra Reyes Andres Remigio",
"2063": "Ramon Rodas Katherine Fernanda",
"2064": "Rodriguez Rodriguez Paul Esteban",
"2065": "Romero Calero Stefania Magdalena",
"2066": "Tenezaca Maza Adriana Nube",
"2067": "Uzhca Gonzalez Jessica Karina",
"2068": "Velez Arcentales Jenny Isabel",
"2069": "Yanez Arevalo Maria Belen",
"2070": "Baculima Bueno Jessica Priscila",
"2071": "Bermeo Zuna Diego Alejandro",
"2072": "Carchi Ordonez Gabriela Elizabeth",
"2073": "Lata Sinchi Ana Lucia",
"2074": "Maita Robles John Christian",
"2075": "Mejia Lojano Gloria Beatriz",
"2076": "Morales Figueroa Miriam Susana",
"2077": "Murillo Pinos Ana Lucia",
"2078": "Romero Carpio Joseline Lorena",
"2079": "Ulloa Vintimilla Hernan Marcelo",
"2080": "Valdivieso Aviles Jessica Daniela",
"2081": "Vasquez Sari Tatiana Cecibel",
"2082": "Vivar Rivadeneira Susana Elizabeth",
"2083": "Barrera Barrera Edgar Lizandro",
"2084": "Gonzalez Gonzalez Wilmer David",
"2085": "Guaman Bazan Blanca Gladys",
"2086": "Guaman Fernandez Mercy Gabriela",
"2087": "Gutierrez Calle Maricela Janeth",
"2088": "Munoz Perez Carmen Gardenia",
"2089": "Piedra Piedra Martha Cecila",
"2090": "Tobar Cruz Alisson Joan",
"2091": "Ulloa Yunga Martha Lucia",
"2092": "Pillajo Vanegas Jorge Luis",
"2093": "Velez Montenegro Nohemy Veronica",
"2094": "Tandazo Hernandez Estefania",
"2095": "Byron Lopez",
"2096": "Greta Andrade",
"2097": "Janeth Mendez",
"2098": "Maria Elena Cardenas",
"2099": "Byron Benavides",
"2100": "Katerine Pauzhi",
"2101": "Andrea Guanuchi",
"2102": "Paul Carpio",
"2103": "Maria Belen Ochoa",
"2104": "Christian Cando",
"2105": "Marcimex Jhon Byron Paula Calle"
}
for key, value in dictionary.items():
if value == name:
return key # Devuelve la clave asociada al nombre validar si es el numero o mail
return None
\ No newline at end of file
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